public function actionShow($id) { $page = Page::findOne(['id' => $id]); if (is_null($page)) { throw new NotFoundHttpException(); } return $this->render('index.tpl', ['page' => $page]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $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; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'title__pl', $this->title__pl])->andFilterWhere(['like', 'body__pl', $this->body__pl]); return $dataProvider; }
/** * @param Event $event */ public function deleteNiceUrl(Event $event) { /** @var Page $page */ $page = $event->sender; NiceUrl::deleteAll(['object_class' => Page::className(), 'object_id' => $page->id]); }
/** * @param integer $id * * @return Page * * @throws NotFoundHttpException */ protected function findModel($id) { if (($model = Page::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }