PodcastsController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 = str_replace("/","",$topic);
  38. $topic = NewsTopic::find()->andWhere(['url'=>$topic])->one();
  39. if( !$topic instanceof NewsTopic ) throw new NotFoundHttpException("Раздел не найден");
  40. return $this->render("archive/index",["topic"=>$topic]);
  41. }
  42. }