Yii實(shí)現(xiàn)復(fù)選框批量操作實(shí)例代碼
整理文檔,搜刮出一個Yii實(shí)現(xiàn)復(fù)選框批量操作實(shí)例代碼,稍微整理精簡一下做下分享。
在視圖下
<?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;">設(shè)置狀態(tài)</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('請至少選擇一個項(xiàng)目。'); return ; } //這里是傳遞的url post方法 $.post("index.php?r=user/status",{'ids[]':data,'status':$('#status').val()}, function (data) { if (data=='ok') { alert('設(shè)置狀態(tài)成功!'); }else{ alert('設(shè)置狀態(tài)失敗,請重試!'); } window.open('index.php?r=user/admin','mainFrame');; }); } </script>
在Model中的search()函數(shù)
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, ));
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Yii2 批量插入、更新數(shù)據(jù)實(shí)例
- YII框架批量插入數(shù)據(jù)的方法
- Yii框架批量插入數(shù)據(jù)擴(kuò)展類的簡單實(shí)現(xiàn)方法
- Yii2如何批量添加數(shù)據(jù)
- 淺析Yii2 gridview實(shí)現(xiàn)批量刪除教程
- yii2使用GridView實(shí)現(xiàn)數(shù)據(jù)全選及批量刪除按鈕示例
- JavaScript中全選、全不選、反選、無刷新刪除、批量刪除、即點(diǎn)即改入庫(在yii框架中操作)的代碼分享
- Yii中CGridView實(shí)現(xiàn)批量刪除的方法
- Yii2.0實(shí)現(xiàn)的批量更新及批量插入功能示例
相關(guān)文章
PHP生成圖片驗(yàn)證碼、點(diǎn)擊切換實(shí)例
這篇文章主要介紹了PHP生成圖片驗(yàn)證碼實(shí)例,同時介紹了點(diǎn)擊切換(看不清?換一張)效果實(shí)現(xiàn)方法,需要的朋友可以參考下2014-06-06thinkphp解決數(shù)據(jù)傳入數(shù)據(jù)庫中特殊字符的問題小結(jié)
這篇文章主要介紹了thinkphp解決數(shù)據(jù)傳入數(shù)據(jù)庫中特殊字符的問題,為了解決這個問題,你需要確保在插入數(shù)據(jù)庫之前,不對文本內(nèi)容進(jìn)行HTML實(shí)體編碼,需要的朋友可以參考下2024-03-03Yii2框架實(shí)現(xiàn)登陸添加驗(yàn)證碼功能示例
這篇文章主要介紹了Yii2框架實(shí)現(xiàn)登陸添加驗(yàn)證碼功能,結(jié)合實(shí)例形式分析了Yii2框架登陸添加驗(yàn)證碼相關(guān)的設(shè)置、控制器及視圖操作技巧,需要的朋友可以參考下2018-07-07PHP+Ajax異步帶進(jìn)度條上傳文件實(shí)例
這篇文章主要介紹了PHP+Ajax異步帶進(jìn)度條上傳文件實(shí)例代碼,代碼簡單易懂,非常不錯,具有參考借鑒價(jià)值,需要的朋友可以參考下。2016-11-11制作安全性高的PHP網(wǎng)站的幾個實(shí)用要點(diǎn)
這篇文章主要介紹了制作安全性高的PHP網(wǎng)站的幾個實(shí)用要點(diǎn),需要的朋友可以參考下2014-12-12PHP用正則匹配form表單中所有元素的類型和屬性值實(shí)例代碼
這篇文章主要介紹了PHP用正則匹配form表單中所有元素的類型和屬性值的方法,文中給出了完整的實(shí)例代碼,大家可以直接參考學(xué)習(xí),下面來一起看看吧。2017-02-02