tiandi2050 2015-08-19 10:54:05 4375次浏览 1条评论 3 3 0

搜索的形式:

第一种,点击空白处:

<?php
$data=['0'=>'已删除','10'=>'正常','1'=>'锁定'];
?>
<table style='height:80px'>  

<tr id="w0-filters" class="filters">
<td>
<div class="col-md-4"><span style='padding:0 15px'>状态</span><?=Html::activeDropDownList($searchModel, 'status', $data, ['class'=>'form-control input-sm','prompt' => '状态','style'=>'width:150px'])?></div>
</td>
<td>
<div class="col-md-4"><span style='padding:0 15px'>性别</span><?=Html::activeDropDownList($searchModel, 'sex', $cate, ['class'=>'form-control input-sm','prompt' => '性别','style'=>'width:150px'])?></div>
</td>

<td>
<span style='padding:0 15px'>用户名</span><input type="text" class="form-control" style='width:100px' name="UserSearch[mobile_phone]" value="<?=$searchModel->username ?>"/></td>
<td>

<td>
<span style='padding:0 15px'>手机号码</span><input type="text" class="form-control" style='width:100px' name="UserSearch[email]" value="<?=$searchModel->email ?>"/></td>
<td>

<td>
<span style='padding:0 15px'>邮箱</span><input type="text" class="form-control" style='width:100px' name="UserSearch[mobile_phone]" value="<?=$searchModel->mobile_phone ?>"/></td>
<td> 
</tr> 

</table>

第二种,点击搜索:

<?php $form = ActiveForm::begin([

'action' => ['index'],
'method' => 'get',
]); ?>

<?= $form->field($model, 'id') ?>

<?= $form->field($model, 'username') ?>

<?= $form->field($model, 'auth_key') ?>

<?= $form->field($model, 'password_hash') ?>

<?= $form->field($model, 'password_reset_token') ?>

<td>
<span style='padding:0 15px'>邮箱</span><input type="text" class="form-control" style='width:100px' name="UserSearch[mobile_phone]" value="<?=$searchModel->mobile_phone ?>"/></td>
<td>

<div class="form-group">
<?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('重置', ['class' => 'btn btn-default']) ?>
</div>

<?php ActiveForm::end(); ?> 

这是Yii2搜索的两种用法:

<?=Html::activeDropDownList($searchModel, 'brand_id', ArrayHelper::map(Brand::find()->where(['user_id'=>\Yii::$app->user->id])->asArray()->all(),'id','name_zh'), ['class'=>'form-control input-sm','prompt' => '请选择品牌'])?>

<?=Html::activeTextInput($searchModel, 'name', ['class'=>'form-control input-sm col-md-3', 'placeholder'=>'输入您要查找的店铺关键字'])?>

可以随意按照自己的想法更改搜索框的样式

觉得很赞
您需要登录后才可以评论。登录 | 立即注册