PHP--Yii框架复选框批量操作的方法
2017-05-16 23:08:19
•
阅读
打赏
本文主要介绍了PHP--Yii框架实现复选框批量操作实例代码,欢迎大家的学习。
在视图页面php文件:
$this->widget('zii.widgets.grid.CGridView',
array('id' => 'user-grid',
'dataProvider' => $model->search(),//Model里需要有个search()方法,$model是Controller中传递的Model对象
'filter'=>$model,
'columns' => array(
array(
'selectableRows' => 2,
'class' => 'CCheckBoxColumn',
'headerHtmlOptions' => array('width' => '18px', 'align' => 'center'),
'checkBoxHtmlOptions' => array('name' => 'ids[]', 'align' => 'center'),
),
'homework_numberID',
'type',
'target',
'state',
'author_id',
array('name' => 'state', 'type' => 'raw', 'value' => '($data->state =="not_read" ?"未读":"已审核")'),
array('name'=>'passRecord','type'=>'date'),
array('name' => 'submit_time', 'type' => 'date'),
array('class' => 'CButtonColumn',)
)
)
);
?>
<select name="status" id="status">
<option value="1">通过</option>
<option value="0">不通过</option>
</select>
<button type="button" onclick="setStatus();" style="width:120px;">设置状态</button>
<script type="text/javascript"> function getData() {
var data = new Array();
$("input:checkbox[name='ids[]']").each(function () {
if ($(this).attr("checked")) {
data.push($(this).val());
}
});
return data;
}
function setStatus() {
var data = getData();
if (data.length < 1) {
alert('请至少选择一个项目。');
return;
}
//这里是传递的url post方法
$.post("index.php?r=user/status", {'ids[]': data, 'status': $('#status').val()}, function (data) {
if (data == 'ok') {
alert('设置状态成功!');
} else {
alert('设置状态失败,请重试!');
}
window.open('index.php?r=user/admin', 'mainFrame');
});
}
</script>
在Model中的search()函数
public function search() {
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria->with = array('author'); //添加了和 author 的渴求式加载
$this->state = "not_passed";
$criteria->compare('state', $this->state);
//这里添加了一个 compare, username 是 User 表的字段,$this->name 是我们添加的属性,true 为模糊搜索
$criteria->compare('username', $this->name, true);
return new CActiveDataProvider($this, array('criteria' => $criteria,));
}
以上就是本文PHP--Yii框架复选框批量操作的方法的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。
相关推荐
深度学习 -- 损失函数
深度残差网络(Deep Residual Networks (ResNets))
深度学习 -- 激活函数
神经网络训练 -- 调整学习速率
生成对抗网络(GAN)改进与发展
生成对抗网络(GAN)优点与缺点
生成对抗网络(GAN)的训练
生成对抗网络(GAN)基本原理
生成模型与判别模型