/** * Finds the NewsCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return NewsCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $model = NewsCategory::find()->where(['id' => $id])->with('translations')->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionView($slug) { $category = NewsCategory::find()->active()->language()->andWhere(['slug' => $slug])->one(); if (!$category) { throw new NotFoundHttpException(); } $query = News::find()->active()->language()->category($category); $pages = new Pagination(['totalCount' => $query->count(), 'defaultPageSize' => Yii::t('f/news', 'defaultPageSize'), 'forcePageParam' => false]); $news = $query->order()->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('view', ['category' => $category, 'news' => $news, 'pages' => $pages]); }