public function actionView($alias) { $model = Pages::findOne(['alias' => $alias]); if ($model !== null) { return $this->render('view', ['model' => $model]); } else { throw new NotFoundHttpException('The requested post does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Pages::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'FROM_UNIXTIME(created_at, "%d.%m.%Y")' => $this->created_at]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $model = new Pages(); $query = Pages::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'removed' => $this->removed, 'status' => $this->status, 'locked' => $this->locked]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionDelete($id) { Pages::findOne($id)->delete(); Yii::$app->getSession()->setFlash('success', 'Страница успешно удалена.'); return $this->redirect(['index']); }