[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], ]; } /** * Lists all Page models. * @return mixed */ public function actionIndex() { $searchModel = new SearchPage(); $_GET['lang_id'] = 1; return $this->render('index', [ 'dataProvider' => new SqlDataProvider([ 'sql' => SearchPage::getList(Yii::$app->request->get()), 'pagination' => [ 'pagesize' => 30, ], 'sort' => [ 'attributes' => [ 'page_id', 'date_add', 'title', 'show', ] ] ]), 'searchModel' => $searchModel, ]); } /** * Displays a single Page model. * @param integer $id * @return mixed */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); $page_lang = new PageLang(); if ($model->validate() && $page_lang->load(Yii::$app->request->post()) && $model->load(Yii::$app->request->post())) { $model->save(); $page_lang->page_id = $model->page_id; $page_lang->lang_id = 1; $page_lang->save(); return $this->redirect(['view', 'id' => $model->page_id]); } else { return $this->render('create', [ 'model' => $model, 'page_lang' => $page_lang, ]); } } /** * Updates an existing Page model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $page_lang = PageLang::find()->where(['page_id' => $id, 'lang_id' => 1])->one(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->page_id]); } else { return $this->render('update', [ 'model' => $model, 'page_lang' => $page_lang, ]); } } /** * Deletes an existing Page model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the Page model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Page the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Page::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }