[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => [ 'POST' ], ], ], 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => [ '@' ], ], ], ], ]; } public function actions() { return [ 'index' => [ 'class' => Index::className(), 'columns' => [ 'title' => [ 'type' => Index::ACTION_COL, ], 'categories' => [ 'type' => Index::RELATION_COL, 'columnConfig' => [ 'relationField' => 'title', ], ], 'updated_at' => [ 'type' => Index::DATETIME_COL, ], 'sort' => [ 'type' => Index::POSITION_COL, ], 'in_menu' => [ 'type' => Index::STATUS_COL, ], ], 'model' => Page::className(), 'hasLanguage' => true, 'enableMassDelete' => true, 'modelPrimaryKey' => 'id', ], 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), 'view' => [ 'class' => View::className(), 'model' => Page::className(), 'hasAlias' => true, 'hasGallery' => true, 'languageFields' => [ [ 'name' => 'title', 'type' => Form::STRING, ], [ 'name' => 'body', 'type' => Form::WYSIWYG, ], ], 'fields' => [ [ 'name' => 'image_id', 'type' => Form::IMAGE, ], [ 'name' => 'categoryIds', 'type' => Form::RELATION, 'relationAttribute' => 'title', 'relationName' => 'categories', 'multiple' => true, ], ], ], 'delete' => [ 'class' => Delete::className(), ], ]; } public function findModel($id) { $model = Page::find() ->with('languages') ->where([ 'id' => $id ]) ->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } public function newModel() { return new Page(); } public function deleteModel($id) { $page = Page::find() ->with('languages.alias') ->where( [ 'id' => $id, ] ) ->one(); $langs = call_user_func( [ $page, 'getVariationModels', ] ); foreach ($langs as $lang) { if ($lang->alias !== null) { $lang->alias->delete(); } } return $page->delete(); } protected static function fieldsConfig() { return [ 'model' => Page::className(), 'hasAlias' => true, 'hasGallery' => true, 'languageFields' => [ [ 'name' => 'title', 'type' => Form::STRING, ], [ 'name' => 'body', 'type' => Form::WYSIWYG, ], ], 'fields' => [ [ 'name' => 'image_id', 'type' => Form::IMAGE, ], [ 'name' => 'categoryIds', 'type' => Form::RELATION, 'relationAttribute' => 'title', 'relationName' => 'categories', 'multiple' => true, ], [ 'name' => 'in_menu', 'type' => Form::BOOL, ], [ 'name' => 'sort', 'type' => Form::NUMBER, ], ], ]; } public function actionSettings() { return $this->render('settings'); } }