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 | use common\models\blog\Category; | 
| 7 | 7 | use common\models\blog\Tag; | 
| 8 | 8 | use yii\data\ActiveDataProvider; | 
| 9 | + use yii\db\ActiveQuery; | |
| 9 | 10 | use yii\web\Controller; | 
| 10 | 11 | use yii\web\NotFoundHttpException; | 
| 11 | 12 | |
| ... | ... | @@ -47,7 +48,9 @@ | 
| 47 | 48 | ) | 
| 48 | 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 | 126 | ->where(['status' => true]) | 
| 124 | 127 | ->orderBy([ 'sort' => SORT_ASC ]) | 
| 125 | 128 | ->one(); | 
| 126 | - | |
| 129 | + if (empty($model)){ | |
| 130 | + throw new NotFoundHttpException(); | |
| 131 | + } | |
| 127 | 132 | $dataProvider = new ActiveDataProvider( | 
| 128 | 133 | [ | 
| 129 | 134 | 'query' => $model->getArticles() | 
| ... | ... | @@ -188,9 +193,15 @@ | 
| 188 | 193 | ->with( | 
| 189 | 194 | [ | 
| 190 | 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 | 205 | ->where(['blog_article.status' => true]) | 
| 195 | 206 | ->orderBy( | 
| 196 | 207 | [ | 
| ... | ... | @@ -229,10 +240,16 @@ | 
| 229 | 240 | ->with( | 
| 230 | 241 | [ | 
| 231 | 242 | 'language', | 
| 232 | - 'categories.language', | |
| 233 | 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 | 253 | ->andWhere([ 'status' => true ]) | 
| 237 | 254 | ->one(); | 
| 238 | 255 | ... | ... |