123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace app\controllers;
- use app\models\News;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- class NewsController extends Controller
- {
- /**
- * @param int $id
- * @return string
- */
- public function actionView(int $id):string {
- $model = $this->findModel($id);
- if(!$model instanceof News) throw new NotFoundHttpException("Новость не найдена");
- return $this->render('view',['model'=>$model]);
- }
- public function actionStoryslugView($storyslug):string
- {
- $model = News::find()->andWhere(['alias'=>$storyslug])->one();
- if(!$model instanceof News) throw new NotFoundHttpException("Новость не найдена");
- return $this->render('view',['model'=>$model]);
- }
- private function findModel($id)
- {
- return News::find()->andWhere(['id'=>$id])->one();
- }
- }
|