Organize search with search from in main layout


I’m trying to organize search on my site. I have added form in the main layout so that search should be available on any page.

I have created Search model

class Search extends Model


    public $request;

    public function rules()


        return [

        	['request', 'safe'],

        	['request', 'string', 'max' => 255],            




SearchController controller:

use frontend\models\Search;

class SearchController extends \yii\web\Controller


    public function actionIndex()


    	$model = new Search();

    	if ($model->load(Yii::$app->request->post()) && $model->validate())


			$request = $model->request;	

			if ($request == 'test')

    		return $this->redirect('songs/success');


    	else return $this->redirect(Url::to('site/error'));



and in layout I have something like:

$form = ActiveForm::begin([

'action' => Url::to('search/index')]);

<?= $form->field($model, 'request')->textInput(['maxlength' => true])->label(false) ?> 

<?= Html::submitInput('', ['style' => 'display:none;', 'id' => 'Search']);?>


But I can’t get model details in contoller after I submit the form.

Please help to understand how it is better to organize this search.

Thank you

Probably "$model" in the layout is not an instance of "Search" model.