示例#1
0
 /**
  * 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]);
     }
 }
 /**
  * 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]);
 }