VideoController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\controllers;
  3. use app\models\base\NewsTopic;
  4. use app\models\News;
  5. use yii\web\Controller;
  6. use yii\web\NotFoundHttpException;
  7. class VideoController extends Controller
  8. {
  9. //public $viewTheme = "dark";
  10. public function actionIndex($topic=NULL)
  11. {
  12. $topic_id = 128;
  13. return $this->render("index",["topic_id"=>$topic_id]);
  14. }
  15. /**
  16. * @param int $id
  17. * @return string
  18. */
  19. public function actionView(int $id):string {
  20. $model = $this->findModel($id);
  21. if(!$model instanceof News) throw new NotFoundHttpException("Новость не найдена");
  22. return $this->render('view',['model'=>$model]);
  23. }
  24. public function actionStoryslugView($storyslug):string
  25. {
  26. $model = News::find()->andWhere(['alias'=>$storyslug])->one();
  27. if(!$model instanceof News) throw new NotFoundHttpException("Новость не найдена");
  28. return $this->render('view',['model'=>$model]);
  29. }
  30. private function findModel($id)
  31. {
  32. return News::find()->andWhere(['id'=>$id])->one();
  33. }
  34. public function actionTopic($topic){
  35. $topic = NewsTopic::find()->andWhere(['url'=>$topic])->one();
  36. if(!$topic instanceof NewsTopic) throw new NotFoundHttpException("Страница не найдена");
  37. return $this->render("archive/index",["topic"=>$topic]);
  38. }
  39. }