国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

Yii實現復選框批量操作實例代碼

2024-05-04 23:55:55
字體:
來源:轉載
供稿:網友

整理文檔,搜刮出一個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,     )); 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 伽师县| 张家港市| 永定县| 霍林郭勒市| 奇台县| 宣恩县| 柳河县| 平原县| 沧州市| 肃北| 得荣县| 惠水县| 宿松县| 辰溪县| 长子县| 获嘉县| 泽库县| 东丰县| 泰兴市| 泌阳县| 大理市| 乌兰察布市| 南昌县| 宜兴市| 肇源县| 博爱县| 赣州市| 阳曲县| 西盟| 玛多县| 婺源县| 大埔区| 沂南县| 嘉黎县| 龙井市| 巴中市| 天门市| 东平县| 石阡县| 偃师市| 西青区|