Yii2 中使用搜索的相关教程 [ 2.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'=>'输入您要查找的店铺关键字'])?>
可以随意按照自己的想法更改搜索框的样式
tiandi2050
注册时间:2015-05-25
最后登录:2017-03-28
在线时长:16小时6分
最后登录:2017-03-28
在线时长:16小时6分
- 粉丝10
- 金钱235
- 威望60
- 积分995
共 1 条评论
asdad