$topic]); if(!$topic instanceof NewsTopic){ $topic = new \stdClass(); $topic->id = NULL; } $news_query = \app\models\News::find()->joinWith('topics t')->andFilterWhere(['t.id'=>$topic->id]); $dateRange = \Yii::$app->request->get('daterange',NULL); if(!is_null($dateRange) && $dateRange!=""){ $dateRange = explode(" — ",$dateRange); $dateRange[0] = date("Y-m-d 00:00:01",strtotime($dateRange[0])); $dateRange[1] = date("Y-m-d 23:59:59",strtotime($dateRange[1])); $news_query->andWhere(["BETWEEN","dt_pub",$dateRange[0],$dateRange[1]]); } return $this->render("index",["topic"=>$topic,"daterange"=>$dateRange,"news_query"=>$news_query]); } /** * @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(); } }