SearchWidget.php 1.04 KB
<?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,
                ]
            );
        }
    }