PodcastsController.php 1.5 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 PodcastsController extends Controller
  8. {
  9. //public $viewTheme = "dark";
  10. //public $viewPath = "@app/views/news";
  11. public function actionIndex($topic=NULL)
  12. {
  13. $this->viewPath = "@app/views/podcasts";
  14. $topic_id = 127;
  15. return $this->render("index",["topic_id"=>$topic_id]);
  16. }
  17. /**
  18. * @param int $id
  19. * @return string
  20. */
  21. public function actionView(int $id):string {
  22. $model = $this->findModel($id);
  23. if(!$model instanceof News) throw new NotFoundHttpException("Новость не найдена");
  24. return $this->render('view',['model'=>$model]);
  25. }
  26. public function actionStoryslugView($storyslug):string
  27. {
  28. $model = News::find()->andWhere(['alias'=>$storyslug])->one();
  29. if(!$model instanceof News) throw new NotFoundHttpException("Новость не найдена");
  30. return $this->render('view',['model'=>$model]);
  31. }
  32. private function findModel($id)
  33. {
  34. return News::find()->andWhere(['id'=>$id])->one();
  35. }
  36. public function actionTopic($topic){
  37. $topic = NewsTopic::find()->andWhere(['url'=>$topic])->one();
  38. if( !$topic instanceof NewsTopic ) throw new NotFoundHttpException("Раздел не найден");
  39. return $this->render("archive/index",["topic"=>$topic]);
  40. }
  41. }