Не работает поиск с dropdownlist
Cам поиск работает, но не передается значение dropdownlist
models
namespace frontend\models;
use yii\base\Model;
class Search extends Model
{
public $q;
public $d;
public function rules()
{
return [
['q', 'string']
];
}
}
SiteController
public function actionSearch()
{
$model = new Search();
$q=Yii::$app->getRequest()->getQueryParam('q');
$d=Yii::$app->getRequest()->getQueryParam('d');
if ($d[0]){
$query = Post::find()->where(['like','title', $q]);
}
else {
$query = Post::find()->where(['like','keywords', $q])->orWhere(['like','text', $q]);
}
$pages = new \yii\data\Pagination(['totalCount' => $query->count(), 'pageSize' => 4 ]);
$posts = $query->offset($pagin->offset)->limit($pagin->limit)->all();
return $this->render('recipes', compact('posts', 'pages'));
}
views/site/recipes.php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\widgets\ActiveField;
use yii\helpers\ArrayHelper;
use frontend\models\Search;
$model = new Search();
?>
<div class="spoil">
<div class="spoil_title">
ПОИСК
</div>
<div class="spoil_body">
<div class="Search">
<?php $form=ActiveForm::begin(); ?>
<?= $form->field($model, 'q')->label('')->textInput(['class'=>'input_search' ]) ?>
<?= $form->field($model, 'd')->dropDownList(['0' => 'Найти в заголовке','1'=>'Найти в тексте и ключевых словах'])?>
<div>
<button type"submit" class="btn btn-primary">Submit</button>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
<div class="recepts">
<? if (!empty($posts)): ?>
<?php foreach ($posts as $post): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><a href="<?= yii\helpers\Url::to([/*'post/view',*/view, 'id' => $post->id])?>"><?=$post->title?></a></h3>
</div>
<div class="panel-body">
<?=$post->excerpt?>
</div>
</div>
<?php endforeach; ?>
<?= \yii\widgets\LinkPager::widget(['pagination' => $pages]) ?>
<?php endif; ?>
</div>