Commit b6fc53c29f895df188445859f0ba439d68d213a6
1 parent
3118df3a
-Blog ready
Showing
7 changed files
with
81 additions
and
91 deletions
Show diff stats
frontend/controllers/BlogController.php
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | */ | 16 | */ |
17 | class BlogController extends Controller | 17 | class BlogController extends Controller |
18 | { | 18 | { |
19 | - public function actionIndex() | 19 | + public function actionIndex($q = '') |
20 | { | 20 | { |
21 | $tags = Tag::find() | 21 | $tags = Tag::find() |
22 | ->with( | 22 | ->with( |
@@ -33,11 +33,18 @@ | @@ -33,11 +33,18 @@ | ||
33 | 'created_at' => SORT_DESC, | 33 | 'created_at' => SORT_DESC, |
34 | ] | 34 | ] |
35 | ) | 35 | ) |
36 | - ->with( | 36 | + ->joinWith( |
37 | [ | 37 | [ |
38 | 'lang', | 38 | 'lang', |
39 | 'categories.lang', | 39 | 'categories.lang', |
40 | ] | 40 | ] |
41 | + ) | ||
42 | + ->andFilterWhere( | ||
43 | + [ | ||
44 | + 'like', | ||
45 | + 'blog_article_lang.title', | ||
46 | + $q, | ||
47 | + ] | ||
41 | ), | 48 | ), |
42 | 'pagination' => [ | 49 | 'pagination' => [ |
43 | 'pageSize' => 3, | 50 | 'pageSize' => 3, |
@@ -57,11 +64,11 @@ | @@ -57,11 +64,11 @@ | ||
57 | public function actionArticle($id) | 64 | public function actionArticle($id) |
58 | { | 65 | { |
59 | $model = $this->findModel($id); | 66 | $model = $this->findModel($id); |
60 | - | 67 | + |
61 | $tags = Tag::find() | 68 | $tags = Tag::find() |
62 | ->with([ 'lang' ]) | 69 | ->with([ 'lang' ]) |
63 | ->all(); | 70 | ->all(); |
64 | - | 71 | + |
65 | return $this->render( | 72 | return $this->render( |
66 | 'view', | 73 | 'view', |
67 | [ | 74 | [ |
@@ -80,7 +87,7 @@ | @@ -80,7 +87,7 @@ | ||
80 | ] | 87 | ] |
81 | ) | 88 | ) |
82 | ->all(); | 89 | ->all(); |
83 | - | 90 | + |
84 | /** | 91 | /** |
85 | * @var Category $model | 92 | * @var Category $model |
86 | */ | 93 | */ |
@@ -96,7 +103,7 @@ | @@ -96,7 +103,7 @@ | ||
96 | ] | 103 | ] |
97 | ) | 104 | ) |
98 | ->one(); | 105 | ->one(); |
99 | - | 106 | + |
100 | $dataProvider = new ActiveDataProvider( | 107 | $dataProvider = new ActiveDataProvider( |
101 | [ | 108 | [ |
102 | 'query' => $model->getArticles() | 109 | 'query' => $model->getArticles() |
@@ -116,7 +123,7 @@ | @@ -116,7 +123,7 @@ | ||
116 | ], | 123 | ], |
117 | ] | 124 | ] |
118 | ); | 125 | ); |
119 | - | 126 | + |
120 | return $this->render( | 127 | return $this->render( |
121 | 'category', | 128 | 'category', |
122 | [ | 129 | [ |
@@ -136,7 +143,7 @@ | @@ -136,7 +143,7 @@ | ||
136 | ] | 143 | ] |
137 | ) | 144 | ) |
138 | ->all(); | 145 | ->all(); |
139 | - | 146 | + |
140 | /** | 147 | /** |
141 | * @var Category $model | 148 | * @var Category $model |
142 | */ | 149 | */ |
@@ -152,7 +159,7 @@ | @@ -152,7 +159,7 @@ | ||
152 | ] | 159 | ] |
153 | ) | 160 | ) |
154 | ->one(); | 161 | ->one(); |
155 | - | 162 | + |
156 | $dataProvider = new ActiveDataProvider( | 163 | $dataProvider = new ActiveDataProvider( |
157 | [ | 164 | [ |
158 | 'query' => $model->getArticles() | 165 | 'query' => $model->getArticles() |
@@ -172,7 +179,7 @@ | @@ -172,7 +179,7 @@ | ||
172 | ], | 179 | ], |
173 | ] | 180 | ] |
174 | ); | 181 | ); |
175 | - | 182 | + |
176 | return $this->render( | 183 | return $this->render( |
177 | 'tag', | 184 | 'tag', |
178 | [ | 185 | [ |
@@ -204,7 +211,7 @@ | @@ -204,7 +211,7 @@ | ||
204 | ] | 211 | ] |
205 | ) | 212 | ) |
206 | ->one(); | 213 | ->one(); |
207 | - | 214 | + |
208 | if (empty($model)) { | 215 | if (empty($model)) { |
209 | throw new NotFoundHttpException(\Yii::t('app', 'Article not found')); | 216 | throw new NotFoundHttpException(\Yii::t('app', 'Article not found')); |
210 | } else { | 217 | } else { |
frontend/views/blog/category.php
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | use artbox\core\components\SeoComponent; | 3 | use artbox\core\components\SeoComponent; |
4 | use artbox\weblog\models\Category; | 4 | use artbox\weblog\models\Category; |
5 | use artbox\weblog\models\Tag; | 5 | use artbox\weblog\models\Tag; |
6 | + use frontend\widgets\BlogSearch; | ||
6 | use yii\data\ActiveDataProvider; | 7 | use yii\data\ActiveDataProvider; |
7 | use yii\helpers\Url; | 8 | use yii\helpers\Url; |
8 | use yii\web\View; | 9 | use yii\web\View; |
@@ -78,26 +79,8 @@ _________________________________________________________ --> | @@ -78,26 +79,8 @@ _________________________________________________________ --> | ||
78 | 79 | ||
79 | </div> | 80 | </div> |
80 | </div> | 81 | </div> |
81 | - | ||
82 | - <div class="panel panel-default sidebar-menu"> | ||
83 | - | ||
84 | - <div class="panel-heading"> | ||
85 | - <h3 class="panel-title">Поиск</h3> | ||
86 | - </div> | ||
87 | - | ||
88 | - <div class="panel-body"> | ||
89 | - <form role="search"> | ||
90 | - <div class="input-group"> | ||
91 | - <input type="text" class="form-control" placeholder="Поиск по статьям"> | ||
92 | - <span class="input-group-btn"> | ||
93 | - | ||
94 | - <button type="submit" class="btn btn-template-main"><i class="fa fa-search"></i></button> | ||
95 | - | ||
96 | - </span> | ||
97 | - </div> | ||
98 | - </form> | ||
99 | - </div> | ||
100 | - </div> | 82 | + |
83 | + <?= BlogSearch::widget(); ?> | ||
101 | 84 | ||
102 | <div class="panel sidebar-menu"> | 85 | <div class="panel sidebar-menu"> |
103 | <div class="panel-heading"> | 86 | <div class="panel-heading"> |
frontend/views/blog/index.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | use artbox\core\components\SeoComponent; | 3 | use artbox\core\components\SeoComponent; |
4 | use artbox\weblog\models\Tag; | 4 | use artbox\weblog\models\Tag; |
5 | + use frontend\widgets\BlogSearch; | ||
5 | use yii\data\ActiveDataProvider; | 6 | use yii\data\ActiveDataProvider; |
6 | use yii\helpers\Url; | 7 | use yii\helpers\Url; |
7 | use yii\web\View; | 8 | use yii\web\View; |
@@ -71,26 +72,8 @@ _________________________________________________________ --> | @@ -71,26 +72,8 @@ _________________________________________________________ --> | ||
71 | 72 | ||
72 | </div> | 73 | </div> |
73 | </div> | 74 | </div> |
74 | - | ||
75 | - <div class="panel panel-default sidebar-menu"> | ||
76 | - | ||
77 | - <div class="panel-heading"> | ||
78 | - <h3 class="panel-title">Поиск</h3> | ||
79 | - </div> | ||
80 | - | ||
81 | - <div class="panel-body"> | ||
82 | - <form role="search"> | ||
83 | - <div class="input-group"> | ||
84 | - <input type="text" class="form-control" placeholder="Поиск по статьям"> | ||
85 | - <span class="input-group-btn"> | ||
86 | - | ||
87 | - <button type="submit" class="btn btn-template-main"><i class="fa fa-search"></i></button> | ||
88 | - | ||
89 | - </span> | ||
90 | - </div> | ||
91 | - </form> | ||
92 | - </div> | ||
93 | - </div> | 75 | + |
76 | + <?= BlogSearch::widget(); ?> | ||
94 | 77 | ||
95 | <div class="panel sidebar-menu"> | 78 | <div class="panel sidebar-menu"> |
96 | <div class="panel-heading"> | 79 | <div class="panel-heading"> |
frontend/views/blog/tag.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | use artbox\core\components\SeoComponent; | 3 | use artbox\core\components\SeoComponent; |
4 | use artbox\weblog\models\Tag; | 4 | use artbox\weblog\models\Tag; |
5 | + use frontend\widgets\BlogSearch; | ||
5 | use yii\data\ActiveDataProvider; | 6 | use yii\data\ActiveDataProvider; |
6 | use yii\helpers\Url; | 7 | use yii\helpers\Url; |
7 | use yii\web\View; | 8 | use yii\web\View; |
@@ -77,26 +78,8 @@ _________________________________________________________ --> | @@ -77,26 +78,8 @@ _________________________________________________________ --> | ||
77 | 78 | ||
78 | </div> | 79 | </div> |
79 | </div> | 80 | </div> |
80 | - | ||
81 | - <div class="panel panel-default sidebar-menu"> | ||
82 | - | ||
83 | - <div class="panel-heading"> | ||
84 | - <h3 class="panel-title">Поиск</h3> | ||
85 | - </div> | ||
86 | - | ||
87 | - <div class="panel-body"> | ||
88 | - <form role="search"> | ||
89 | - <div class="input-group"> | ||
90 | - <input type="text" class="form-control" placeholder="Поиск по статьям"> | ||
91 | - <span class="input-group-btn"> | ||
92 | - | ||
93 | - <button type="submit" class="btn btn-template-main"><i class="fa fa-search"></i></button> | ||
94 | - | ||
95 | - </span> | ||
96 | - </div> | ||
97 | - </form> | ||
98 | - </div> | ||
99 | - </div> | 81 | + |
82 | + <?= BlogSearch::widget(); ?> | ||
100 | 83 | ||
101 | <div class="panel sidebar-menu"> | 84 | <div class="panel sidebar-menu"> |
102 | <div class="panel-heading"> | 85 | <div class="panel-heading"> |
frontend/views/blog/view.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | use artbox\weblog\models\Article; | 3 | use artbox\weblog\models\Article; |
4 | use artbox\weblog\models\Tag; | 4 | use artbox\weblog\models\Tag; |
5 | + use frontend\widgets\BlogSearch; | ||
5 | use yii\helpers\Url; | 6 | use yii\helpers\Url; |
6 | use yii\web\View; | 7 | use yii\web\View; |
7 | 8 | ||
@@ -184,26 +185,8 @@ _________________________________________________________ --> | @@ -184,26 +185,8 @@ _________________________________________________________ --> | ||
184 | 185 | ||
185 | </div> | 186 | </div> |
186 | </div> | 187 | </div> |
187 | - | ||
188 | - <div class="panel panel-default sidebar-menu"> | ||
189 | - | ||
190 | - <div class="panel-heading"> | ||
191 | - <h3 class="panel-title">Поиск</h3> | ||
192 | - </div> | ||
193 | - | ||
194 | - <div class="panel-body"> | ||
195 | - <form role="search"> | ||
196 | - <div class="input-group"> | ||
197 | - <input type="text" class="form-control" placeholder="Поиск по статьям"> | ||
198 | - <span class="input-group-btn"> | ||
199 | - | ||
200 | - <button type="submit" class="btn btn-template-main"><i class="fa fa-search"></i></button> | ||
201 | - | ||
202 | - </span> | ||
203 | - </div> | ||
204 | - </form> | ||
205 | - </div> | ||
206 | - </div> | 188 | + |
189 | + <?= BlogSearch::widget(); ?> | ||
207 | 190 | ||
208 | <div class="panel sidebar-menu"> | 191 | <div class="panel sidebar-menu"> |
209 | <div class="panel-heading"> | 192 | <div class="panel-heading"> |
1 | +<?php | ||
2 | + | ||
3 | + namespace frontend\widgets; | ||
4 | + | ||
5 | + use yii\base\Widget; | ||
6 | + | ||
7 | + /** | ||
8 | + * Class BlogSearch | ||
9 | + * | ||
10 | + * @package frontend\widgets | ||
11 | + */ | ||
12 | + class BlogSearch extends Widget | ||
13 | + { | ||
14 | + public function run() | ||
15 | + { | ||
16 | + return $this->render('_blog_search'); | ||
17 | + } | ||
18 | + } | ||
0 | \ No newline at end of file | 19 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + use yii\helpers\Url; | ||
4 | + use yii\web\View; | ||
5 | + | ||
6 | + /** | ||
7 | + * @var View $this | ||
8 | + */ | ||
9 | + | ||
10 | +?> | ||
11 | + | ||
12 | +<div class="panel panel-default sidebar-menu"> | ||
13 | + | ||
14 | + <div class="panel-heading"> | ||
15 | + <h3 class="panel-title">Поиск</h3> | ||
16 | + </div> | ||
17 | + | ||
18 | + <div class="panel-body"> | ||
19 | + <form role="search" action="<?= Url::to([ 'blog/index' ]) ?>" method="GET"> | ||
20 | + <div class="input-group"> | ||
21 | + <input type="text" class="form-control" name="q" placeholder="Поиск по статьям" value="<?= \Yii::$app->request->get( | ||
22 | + 'q', | ||
23 | + '' | ||
24 | + ) ?>"> | ||
25 | + <span class="input-group-btn"> | ||
26 | + | ||
27 | + <button type="submit" class="btn btn-template-main"><i class="fa fa-search"></i></button> | ||
28 | + | ||
29 | + </span> | ||
30 | + </div> | ||
31 | + </form> | ||
32 | + </div> | ||
33 | +</div> |