最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Yii實(shí)現(xiàn)復(fù)選框批量操作實(shí)例代碼

 更新時(shí)間:2017年03月15日 09:00:52   作者:xujing19920814  
本篇文章主要介紹了Yii實(shí)現(xiàn)復(fù)選框批量操作實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

整理文檔,搜刮出一個(gè)Yii實(shí)現(xiàn)復(fù)選框批量操作實(shí)例代碼,稍微整理精簡(jiǎn)一下做下分享。

在視圖下

<?php $this->widget('zii.widgets.grid.CGridView', array(
 'id'=>'user-grid',
 'dataProvider'=>$model->search(),//Model里需要有個(gè)search()方法,$model是Controller中傳遞的Model對(duì)象
// /'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">通過(guò)</option>
  <option value="0">不通過(guò)</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('請(qǐng)至少選擇一個(gè)項(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)失敗,請(qǐng)重試!');
      }
      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); 


    //這里添加了一個(gè) compare, username 是 User 表的字段,$this->name 是我們添加的屬性,true 為模糊搜索 
    //$criteria->compare('username',$this->name,true); 

    return new CActiveDataProvider($this, array( 
     'criteria'=>$criteria, 
    )); 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

莱阳市| 楚雄市| 和林格尔县| 酉阳| 临江市| 靖宇县| 慈溪市| 临洮县| 雷州市| 巴林左旗| 新营市| 揭西县| 鹤山市| 石河子市| 长治县| 葫芦岛市| 龙山县| 自治县| 邯郸县| 滕州市| 韩城市| 大埔区| 新乡市| 西华县| 甘谷县| 保德县| 广丰县| 平南县| 秭归县| 临沭县| 泾阳县| 麻栗坡县| 邹城市| 新昌县| 罗源县| 普安县| 抚松县| 象山县| 灵石县| 安多县| 大埔区|