public function actionArticle($id) { if (!\Yii::$app->user->can('articles.view')) { $this->accessDenied(); } $model = Article::findOne($id); if ($model->parent->root != $this->_rootid) { $model = null; } if (!$model) { throw new NotFoundHttpException(\Yii::t('yii', 'Page not found.')); } return $this->render('article', ['model' => $model]); }
/** * Finds the Article model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Article the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($this->_model = Article::findOne($id)) !== null) { return $this->_model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }