コード例 #1
0
ファイル: BrandServiceImpl.php プロジェクト: xiaomige/giishop
 public function insert(BrandDto $brandDto)
 {
     $brand = new Brand();
     if ($brand->load(['Brand' => ArrayHelper::toArray($brandDto)])) {
         $brand->insert();
         return ArrayHelper::toArray($brand);
     } else {
         return [];
     }
 }
コード例 #2
0
ファイル: BrandController.php プロジェクト: renyinew/funshop
 /**
  * Creates a new Brand model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Brand();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #3
0
 /**
  * Creates a new Brand model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Brand();
     $model->scenario = $model::SCENARIO_CREATE;
     if ($model->load(Yii::$app->request->post())) {
         $transaction = $model->getDb()->beginTransaction();
         try {
             if ($model->validate()) {
                 $model->save(false);
                 $transaction->commit();
                 Yii::$app->session->setFlash('success', 'Brand have been added.');
                 return $this->redirect('index');
             }
         } catch (Exception $e) {
             $transaction->rollBack();
         }
     }
     return $this->render('create', ['model' => $model]);
 }
コード例 #4
0
ファイル: BrandController.php プロジェクト: wordnews/wei_shop
 /**
  * Creates a new Brand model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (!$this->is_access('brand/create')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = new Brand();
     if ($model->load(Yii::$app->request->post())) {
         /* 处理上传的图片 */
         if ($_FILES['Brand']['error']['brand_logo'] === 0) {
             /* 把文件的路劲赋值给image字段 */
             $model->brand_logo = File::uploadImage($model, 'brand_logo', 'other');
         }
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '添加成功');
         }
         return $this->redirect(['index']);
     } else {
         Yii::$app->view->params['meta_title'] = '添加品牌';
         return $this->render('create', ['model' => $model]);
     }
 }