SearchWidget.php
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace frontend\widgets;
/**
* User: timur
* Date: 28.01.18
* Time: 12:36
*/
use yii\base\Widget;
/**
* Class SearchWidget
*
* @package frontend\widgets
* @property string $route
* @property string $paramForSearch
*/
class SearchWidget extends Widget
{
public $route;
public $paramForSearch = 'title';
public function init()
{
parent::init();
if (!isset($this->route)) {
// by default route is the same as view in which it was used
$this->route = \Yii::$app->controller->id . "/" . \Yii::$app->controller->action->id;
}
}
public function run()
{
return $this->render(
'search_view',
[
'route' => $this->route,
'paramForSearch' => $this->paramForSearch,
]
);
}
}