VideoController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 = str_replace("/","",$topic);
  36. $topic = NewsTopic::find()->andWhere(['url'=>$topic])->one();
  37. if(!$topic instanceof NewsTopic) throw new NotFoundHttpException("Страница не найдена");
  38. return $this->render("archive/index",["topic"=>$topic]);
  39. }
  40. }