Commit 083b028f96b76acaeb60cca20785055c2085d2d6
1 parent
7150a05d
blog categories
Showing
1 changed file
with
23 additions
and
6 deletions
Show diff stats
frontend/controllers/BlogController.php
@@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
6 | use common\models\blog\Category; | 6 | use common\models\blog\Category; |
7 | use common\models\blog\Tag; | 7 | use common\models\blog\Tag; |
8 | use yii\data\ActiveDataProvider; | 8 | use yii\data\ActiveDataProvider; |
9 | + use yii\db\ActiveQuery; | ||
9 | use yii\web\Controller; | 10 | use yii\web\Controller; |
10 | use yii\web\NotFoundHttpException; | 11 | use yii\web\NotFoundHttpException; |
11 | 12 | ||
@@ -47,7 +48,9 @@ | @@ -47,7 +48,9 @@ | ||
47 | ) | 48 | ) |
48 | ->with( | 49 | ->with( |
49 | [ | 50 | [ |
50 | - 'categories.language', | 51 | + 'categories' => function (ActiveQuery $query){ |
52 | + $query->with('language')->where(['status' => true]); | ||
53 | + }, | ||
51 | ] | 54 | ] |
52 | 55 | ||
53 | ) | 56 | ) |
@@ -123,7 +126,9 @@ | @@ -123,7 +126,9 @@ | ||
123 | ->where(['status' => true]) | 126 | ->where(['status' => true]) |
124 | ->orderBy([ 'sort' => SORT_ASC ]) | 127 | ->orderBy([ 'sort' => SORT_ASC ]) |
125 | ->one(); | 128 | ->one(); |
126 | - | 129 | + if (empty($model)){ |
130 | + throw new NotFoundHttpException(); | ||
131 | + } | ||
127 | $dataProvider = new ActiveDataProvider( | 132 | $dataProvider = new ActiveDataProvider( |
128 | [ | 133 | [ |
129 | 'query' => $model->getArticles() | 134 | 'query' => $model->getArticles() |
@@ -188,9 +193,15 @@ | @@ -188,9 +193,15 @@ | ||
188 | ->with( | 193 | ->with( |
189 | [ | 194 | [ |
190 | 'language', | 195 | 'language', |
191 | - 'categories.language', | ||
192 | ] | 196 | ] |
193 | - ) | 197 | + )->with( |
198 | + [ | ||
199 | + 'categories' => function (ActiveQuery $query){ | ||
200 | + $query->with('language')->where(['status' => true]); | ||
201 | + }, | ||
202 | + ] | ||
203 | + | ||
204 | + ) | ||
194 | ->where(['blog_article.status' => true]) | 205 | ->where(['blog_article.status' => true]) |
195 | ->orderBy( | 206 | ->orderBy( |
196 | [ | 207 | [ |
@@ -229,10 +240,16 @@ | @@ -229,10 +240,16 @@ | ||
229 | ->with( | 240 | ->with( |
230 | [ | 241 | [ |
231 | 'language', | 242 | 'language', |
232 | - 'categories.language', | ||
233 | 'tags.language', | 243 | 'tags.language', |
234 | ] | 244 | ] |
235 | - ) | 245 | + )->with( |
246 | + [ | ||
247 | + 'categories' => function (ActiveQuery $query){ | ||
248 | + $query->with('language')->where(['status' => true]); | ||
249 | + }, | ||
250 | + ] | ||
251 | + | ||
252 | + ) | ||
236 | ->andWhere([ 'status' => true ]) | 253 | ->andWhere([ 'status' => true ]) |
237 | ->one(); | 254 | ->one(); |
238 | 255 |