/** * @param $id * @return null|static * @throws NotFoundHttpException */ protected function findModel($id) { if (($model = News::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionGet($newsID) { $news = News::findOne($newsID); if (empty($news)) { throw new NotFoundHttpException("Не найдена новость с идентификатором {$newsID}"); } if (\Yii::$app->request->isAjax) { \Yii::$app->session->setFlash('updated', 'Список комментариев обновлён!'); } return $this->renderPartial('comments', ['news' => $news, 'comments' => new ActiveDataProvider(['query' => $news->getComments()->with('votes'), 'sort' => ['defaultOrder' => ['date' => SORT_ASC]]])]); }
public function actionRedaktsiya() { $news = News::findOne(['id' => '20819']); return $this->actionNews($news->id, true); }
public function actionNewsDetail($id) { $modelSocial = Social::findOne(1); $model = News::findOne($id); return $this->render('news-detail', ['model' => $model, 'modelSocial' => $modelSocial]); }