controllers/AdminController.php
public function actionCreate()
    {//echo __METHOD__."@{$this->module->className()}";
        //$model = new News();
        $model = $this->module->model('News');//var_dump($model->className());
        $model = $model->loadDefaultValues();
        //$modelsI18n = News::prepareI18nModels($model);
        $modelsI18n = $model::prepareI18nModels($model);//var_dump($modelsI18n);exit;

        $activeTab = $this->langCodeMain;

        $created = $this->savePost($model, $modelsI18n);
        if (!$created) {
            return $this->render('create', [
                'model' => $model,
                'modelsI18n' => $modelsI18n,
                'activeTab' => $activeTab,
            ]);
        } else if ($activeTab = $this->modelsHaveErrors($model, $modelsI18n)) { // main record created but exist another errors
            Yii::$app->session->setFlash('warning', Yii::t($this->tcModule, 'Record create but partially'));
            if ($activeTab === true) $activeTab = $this->langCodeMain;
            $errors = $model->errors;
            foreach($modelsI18n as $langCode => $modelI18n) {
                if ($modelI18n->hasErrors()) {
                    $errors += $modelI18n->errors;
                    $activeTab = $langCode;
                    break;
                }
            }
            $error = array_shift($errors); // get only first error
            if (isset($error[0])) {
                Yii::$app->session->setFlash('error', $error[0]);
            }
            return $this->redirect(['update',
                'id' => $model->id,
                'activeTab' => $activeTab,
            ]);
        } else {
            Yii::$app->session->setFlash('success', Yii::t($this->tcModule, 'Record create success'));
            if ($model->aftersave == $model::AFTERSAVE_VIEW) {
                return $this->redirect(['view', 'id' => $model->id]);
            } else {
                return $this->redirect(['index',
                    'page' => $model->page,
                    'id' => $model->id,
                    'sort' => $model->orderBy,
                    //'lang' => Yii::$app->language,
                ]);
            }
        }
    }
public function actionCreate()
    {//echo __METHOD__."@{$this->module->className()}";
        //$model = new News();
        $model = $this->module->model('News');//var_dump($model->className());
        $model = $model->loadDefaultValues();
        //$modelsI18n = News::prepareI18nModels($model);
        $modelsI18n = $model::prepareI18nModels($model);//var_dump($modelsI18n);exit;

        $activeTab = $this->langCodeMain;

        $created = $this->savePost($model, $modelsI18n);
        if (!$created) {
            return $this->render('create', [
                'model' => $model,
                'modelsI18n' => $modelsI18n,
                'activeTab' => $activeTab,
            ]);
        } else if ($activeTab = $this->modelsHaveErrors($model, $modelsI18n)) { // main record created but exist another errors
            Yii::$app->session->setFlash('warning', Yii::t($this->tcModule, 'Record create but partially'));
            if ($activeTab === true) $activeTab = $this->langCodeMain;
            $errors = $model->errors;
            foreach($modelsI18n as $langCode => $modelI18n) {
                if ($modelI18n->hasErrors()) {
                    $errors += $modelI18n->errors;
                    $activeTab = $langCode;
                    break;
                }
            }
            $error = array_shift($errors); // get only first error
            if (isset($error[0])) {
                Yii::$app->session->setFlash('error', $error[0]);
            }
            return $this->redirect(['update',
                'id' => $model->id,
                'activeTab' => $activeTab,
            ]);
        } else {
            Yii::$app->session->setFlash('success', Yii::t($this->tcModule, 'Record create success'));
            if ($model->aftersave == $model::AFTERSAVE_VIEW) {
                return $this->redirect(['view', 'id' => $model->id]);
            } else {
                return $this->redirect(['index',
                    'page' => $model->page,
                    'id' => $model->id,
                    'sort' => $model->orderBy,
                    //'lang' => Yii::$app->language,
                ]);
            }
        }
    }
public function actionCreate ( ) { //echo __METHOD__."@{$this->module->className()}"; //$model = new News(); $ model = $ this -> module -> model ( 'News' ) ; //var_dump($model->className()); $ model = $ model -> loadDefaultValues ( ) ; //$modelsI18n = News::prepareI18nModels($model); $ modelsI18n = $ model :: prepareI18nModels ( $ model ) ; //var_dump($modelsI18n);exit; $ activeTab = $ this -> langCodeMain ; $ created = $ this -> savePost ( $ model , $ modelsI18n ) ; if ( ! $ created ) { return $ this -> render ( 'create' , [ 'model' => $ model , 'modelsI18n' => $ modelsI18n , 'activeTab' => $ activeTab , ] ) ; } else if ( $ activeTab = $ this -> modelsHaveErrors ( $ model , $ modelsI18n ) ) { // main record created but exist another errors Yii :: $ app -> session -> setFlash ( 'warning' , Yii :: t ( $ this -> tcModule , 'Record create but partially' ) ) ; if ( $ activeTab === true ) $ activeTab = $ this -> langCodeMain ; $ errors = $ model -> errors ; foreach ( $ modelsI18n as $ langCode => $ modelI18n ) { if ( $ modelI18n -> hasErrors ( ) ) { $ errors += $ modelI18n -> errors ; $ activeTab = $ langCode ; break ; } } $ error = array_shift ( $ errors ) ; // get only first error if ( isset ( $ error [ 0 ] ) ) { Yii :: $ app -> session -> setFlash ( 'error' , $ error [ 0 ] ) ; } return $ this -> redirect ( [ 'update' , 'id' => $ model -> id , 'activeTab' => $ activeTab , ] ) ; } else { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( $ this -> tcModule , 'Record create success' ) ) ; if ( $ model -> aftersave == $ model :: AFTERSAVE_VIEW ) { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { return $ this -> redirect ( [ 'index' , 'page' => $ model -> page , 'id' => $ model -> id , 'sort' => $ model -> orderBy , //'lang' => Yii::$app->language, ] ) ; } } }
Creates a new News model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new News model . If creation is successful the browser will be redirected to the view page .