Yii实现复选框批量操作实例代码
更新时间:2017年03月15日 09:00:52 作者:xujing19920814
本篇文章主要介绍了Yii实现复选框批量操作实例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
整理文档,搜刮出一个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, ));
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Vagrant(WSL)+PHPStorm+Xdebu 断点调试环境搭建
这篇文章主要介绍了Vagrant(WSL)+PHPStorm+Xdebu 断点调试环境搭建,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2019-12-12php页面,mysql数据库转utf-8乱码,utf-8编码问题总结
一个网站如果需要国际化,就需要将编码从GB2312转成UTF-8,其中有很多的问题需要注意,如果没有转换彻底,将会有很多的编码问题出现!接下来通过本篇文章给大家分享php页面,mysql数据库转utf-8乱码,utf-8编码问题总结,需要的朋友可以参考下2015-08-08PHP+jQuery 注册模块的改进(三):更新到Smarty3.1
本文是PHP+jQuery 注册模块的改进的第三篇,主要记录了讲Smarty更新到最新的3.1版本,是篇非常使用的文章,有需要的朋友可以参考下2014-10-10
最新评论