controllers/AdminController.php
public function actionUpdate($id, $activeTab = null)
    {
        $model = $this->findModel($id);

        if (!Yii::$app->user->can('roleNewsModerator') // user is not moderator
         &&  Yii::$app->user->can('roleNewsAuthor')    // but is author ...
         && !Yii::$app->user->can('updateOwnNews', [   // ... can edit only own post
                'news' => $model,                      //     - if post unvisible - always can
                'canEditVisible'                       //     - but if not visible - see this param
                    => $this->canAuthorEditOwnVisibleArticle,
            ])
        ) {
            if ($this->canAuthorEditOwnVisibleArticle) {
                throw new ForbiddenHttpException(Yii::t($this->tc, 'You can update only your own post'));
            } else {
                throw new ForbiddenHttpException(Yii::t($this->tc, 'You can update only your own post still unvisible'));
            }
        }

        //$modelsI18n = News::prepareI18nModels($model);
        $modelsI18n = $this->module->model('News')->prepareI18nModels($model);

        if (empty($activeTab)) $activeTab = $this->langCodeMain;

        $created = $this->savePost($model, $modelsI18n);

        if (!$created || ($activeTab = $this->modelsHaveErrors($model, $modelsI18n))) {
            return $this->render('update', [
                'model' => $model,
                'modelsI18n' => $modelsI18n,
                'activeTab' => $activeTab,
            ]);
        } else {
            Yii::$app->session->setFlash('success', Yii::t($this->tcModule, 'Record save 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 actionUpdate($id, $activeTab = null)
    {
        $model = $this->findModel($id);

        if (!Yii::$app->user->can('roleNewsModerator') // user is not moderator
         &&  Yii::$app->user->can('roleNewsAuthor')    // but is author ...
         && !Yii::$app->user->can('updateOwnNews', [   // ... can edit only own post
                'news' => $model,                      //     - if post unvisible - always can
                'canEditVisible'                       //     - but if not visible - see this param
                    => $this->canAuthorEditOwnVisibleArticle,
            ])
        ) {
            if ($this->canAuthorEditOwnVisibleArticle) {
                throw new ForbiddenHttpException(Yii::t($this->tc, 'You can update only your own post'));
            } else {
                throw new ForbiddenHttpException(Yii::t($this->tc, 'You can update only your own post still unvisible'));
            }
        }

        //$modelsI18n = News::prepareI18nModels($model);
        $modelsI18n = $this->module->model('News')->prepareI18nModels($model);

        if (empty($activeTab)) $activeTab = $this->langCodeMain;

        $created = $this->savePost($model, $modelsI18n);

        if (!$created || ($activeTab = $this->modelsHaveErrors($model, $modelsI18n))) {
            return $this->render('update', [
                'model' => $model,
                'modelsI18n' => $modelsI18n,
                'activeTab' => $activeTab,
            ]);
        } else {
            Yii::$app->session->setFlash('success', Yii::t($this->tcModule, 'Record save 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 actionUpdate ( $ id , $ activeTab = null ) { $ model = $ this -> findModel ( $ id ) ; if ( ! Yii :: $ app -> user -> can ( 'roleNewsModerator' ) // user is not moderator && Yii :: $ app -> user -> can ( 'roleNewsAuthor' ) // but is author ... && ! Yii :: $ app -> user -> can ( 'updateOwnNews' , [ // ... can edit only own post 'news' => $ model , //     - if post unvisible - always can 'canEditVisible' //     - but if not visible - see this param => $ this -> canAuthorEditOwnVisibleArticle , ] ) ) { if ( $ this -> canAuthorEditOwnVisibleArticle ) { throw new ForbiddenHttpException ( Yii :: t ( $ this -> tc , 'You can update only your own post' ) ) ; } else { throw new ForbiddenHttpException ( Yii :: t ( $ this -> tc , 'You can update only your own post still unvisible' ) ) ; } } //$modelsI18n = News::prepareI18nModels($model); $ modelsI18n = $ this -> module -> model ( 'News' ) -> prepareI18nModels ( $ model ) ; if ( empty ( $ activeTab ) ) $ activeTab = $ this -> langCodeMain ; $ created = $ this -> savePost ( $ model , $ modelsI18n ) ; if ( ! $ created || ( $ activeTab = $ this -> modelsHaveErrors ( $ model , $ modelsI18n ) ) ) { return $ this -> render ( 'update' , [ 'model' => $ model , 'modelsI18n' => $ modelsI18n , 'activeTab' => $ activeTab , ] ) ; } else { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( $ this -> tcModule , 'Record save 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, ] ) ; } } }
Updates an existing News model.
If update is successful, the browser will be redirected to the 'view' page.
@param integer $id
@return mixed
@throws ForbiddenHttpException if user can't edit this news
Updates an existing News model . If update is successful the browser will be redirected to the view page .