controllers/CrudController.php
public function actionCreate()
    {
        $model = Yii::createObject($this->getModelClass());

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            \Yii::$app->getSession()->setFlash('success', $this->getFlashMsg('success'));
            return $this->redirect(ArrayHelper::merge(['view'], $model->getPrimaryKey(true)));
        } else {
            if ($model->hasErrors()) {
                \Yii::$app->getSession()->setFlash('error', $this->getFlashMsg('error'));
            }
            return $this->render($this->viewID, [
                'model' => $model,
            ]);
        }
    }
public function actionCreate()
    {
        $model = Yii::createObject($this->getModelClass());

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            \Yii::$app->getSession()->setFlash('success', $this->getFlashMsg('success'));
            return $this->redirect(ArrayHelper::merge(['view'], $model->getPrimaryKey(true)));
        } else {
            if ($model->hasErrors()) {
                \Yii::$app->getSession()->setFlash('error', $this->getFlashMsg('error'));
            }
            return $this->render($this->viewID, [
                'model' => $model,
            ]);
        }
    }
public function actionCreate ( ) { $ model = Yii :: createObject ( $ this -> getModelClass ( ) ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { \ Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , $ this -> getFlashMsg ( 'success' ) ) ; return $ this -> redirect ( ArrayHelper :: merge ( [ 'view' ] , $ model -> getPrimaryKey ( true ) ) ) ; } else { if ( $ model -> hasErrors ( ) ) { \ Yii :: $ app -> getSession ( ) -> setFlash ( 'error' , $ this -> getFlashMsg ( 'error' ) ) ; } return $ this -> render ( $ this -> viewID , [ 'model' => $ model , ] ) ; } }
Creates a new target model.
If creation is successful, the browser will be redirected to the 'view' page.
@return \yii\web\Response|string
Creates a new target model . If creation is successful the browser will be redirected to the view page .