Commit b6fc53c29f895df188445859f0ba439d68d213a6

Authored by Alexey Boroda
1 parent 3118df3a

-Blog ready

frontend/controllers/BlogController.php
... ... @@ -16,7 +16,7 @@
16 16 */
17 17 class BlogController extends Controller
18 18 {
19   - public function actionIndex()
  19 + public function actionIndex($q = '')
20 20 {
21 21 $tags = Tag::find()
22 22 ->with(
... ... @@ -33,11 +33,18 @@
33 33 'created_at' => SORT_DESC,
34 34 ]
35 35 )
36   - ->with(
  36 + ->joinWith(
37 37 [
38 38 'lang',
39 39 'categories.lang',
40 40 ]
  41 + )
  42 + ->andFilterWhere(
  43 + [
  44 + 'like',
  45 + 'blog_article_lang.title',
  46 + $q,
  47 + ]
41 48 ),
42 49 'pagination' => [
43 50 'pageSize' => 3,
... ... @@ -57,11 +64,11 @@
57 64 public function actionArticle($id)
58 65 {
59 66 $model = $this->findModel($id);
60   -
  67 +
61 68 $tags = Tag::find()
62 69 ->with([ 'lang' ])
63 70 ->all();
64   -
  71 +
65 72 return $this->render(
66 73 'view',
67 74 [
... ... @@ -80,7 +87,7 @@
80 87 ]
81 88 )
82 89 ->all();
83   -
  90 +
84 91 /**
85 92 * @var Category $model
86 93 */
... ... @@ -96,7 +103,7 @@
96 103 ]
97 104 )
98 105 ->one();
99   -
  106 +
100 107 $dataProvider = new ActiveDataProvider(
101 108 [
102 109 'query' => $model->getArticles()
... ... @@ -116,7 +123,7 @@
116 123 ],
117 124 ]
118 125 );
119   -
  126 +
120 127 return $this->render(
121 128 'category',
122 129 [
... ... @@ -136,7 +143,7 @@
136 143 ]
137 144 )
138 145 ->all();
139   -
  146 +
140 147 /**
141 148 * @var Category $model
142 149 */
... ... @@ -152,7 +159,7 @@
152 159 ]
153 160 )
154 161 ->one();
155   -
  162 +
156 163 $dataProvider = new ActiveDataProvider(
157 164 [
158 165 'query' => $model->getArticles()
... ... @@ -172,7 +179,7 @@
172 179 ],
173 180 ]
174 181 );
175   -
  182 +
176 183 return $this->render(
177 184 'tag',
178 185 [
... ... @@ -204,7 +211,7 @@
204 211 ]
205 212 )
206 213 ->one();
207   -
  214 +
208 215 if (empty($model)) {
209 216 throw new NotFoundHttpException(\Yii::t('app', 'Article not found'));
210 217 } else {
... ...
frontend/views/blog/category.php
... ... @@ -3,6 +3,7 @@
3 3 use artbox\core\components\SeoComponent;
4 4 use artbox\weblog\models\Category;
5 5 use artbox\weblog\models\Tag;
  6 + use frontend\widgets\BlogSearch;
6 7 use yii\data\ActiveDataProvider;
7 8 use yii\helpers\Url;
8 9 use yii\web\View;
... ... @@ -78,26 +79,8 @@ _________________________________________________________ -->
78 79  
79 80 </div>
80 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 85 <div class="panel sidebar-menu">
103 86 <div class="panel-heading">
... ...
frontend/views/blog/index.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 use artbox\core\components\SeoComponent;
4 4 use artbox\weblog\models\Tag;
  5 + use frontend\widgets\BlogSearch;
5 6 use yii\data\ActiveDataProvider;
6 7 use yii\helpers\Url;
7 8 use yii\web\View;
... ... @@ -71,26 +72,8 @@ _________________________________________________________ --&gt;
71 72  
72 73 </div>
73 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 78 <div class="panel sidebar-menu">
96 79 <div class="panel-heading">
... ...
frontend/views/blog/tag.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 use artbox\core\components\SeoComponent;
4 4 use artbox\weblog\models\Tag;
  5 + use frontend\widgets\BlogSearch;
5 6 use yii\data\ActiveDataProvider;
6 7 use yii\helpers\Url;
7 8 use yii\web\View;
... ... @@ -77,26 +78,8 @@ _________________________________________________________ --&gt;
77 78  
78 79 </div>
79 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 84 <div class="panel sidebar-menu">
102 85 <div class="panel-heading">
... ...
frontend/views/blog/view.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 use artbox\weblog\models\Article;
4 4 use artbox\weblog\models\Tag;
  5 + use frontend\widgets\BlogSearch;
5 6 use yii\helpers\Url;
6 7 use yii\web\View;
7 8  
... ... @@ -184,26 +185,8 @@ _________________________________________________________ --&gt;
184 185  
185 186 </div>
186 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 191 <div class="panel sidebar-menu">
209 192 <div class="panel-heading">
... ...
frontend/widgets/BlogSearch.php 0 → 100644
  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 19 \ No newline at end of file
... ...
frontend/widgets/views/_blog_search.php 0 → 100644
  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>
... ...