2012-10-23 115 views
3

問:如何從cgridview獲取複選框值?如何從cgridview獲取複選框值?

狀態:我使用CJuiDialog在popbox中創建了cgridview。但是我無法從網格視圖中獲得複選框的值。我得到了500錯誤。

這是我的視圖中打開彈出框

<div style="height:50px;">  
     <?php $imghtml=CHtml::image(Yii::app()->request->baseUrl.'/images/assets/approver.png','', array('style'=>'margin: 5px 0;')); ?> 
      <?php echo CHtml::ajaxLink(
     Yii::t('accrecei',$imghtml), 
     $this->createUrl('implementer/Approverlist', array('id'=>$model->id)), 
     array(
       'onclick'=>'$("#accreceilist").dialog("open"); return false;', 
       'update'=>'#reviewerlist'     
             ), 
     array(
       'id'=>'showaccreceilist', 
       'class'=>'btn btn-info', 
       'title'=>'Add/Remove reviewer', 
       'style'=>'width:25px; float:right; margin-button:20px;',) 
             );?> 
       <div id="reviewerlist"></div> 
     </div> 

這是彈出框

<?php 
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
       'id'=>'reviewerlist', 
       'options'=>array(
        'title'=>Yii::t('accrecei','Reviewer List'), 
        'autoOpen'=>true, 
        'modal'=>'true', 
        'width'=>'750', 
        'height'=>'500', 

       ), 

       )); 
//echo $this->renderPartial('_listing', array('model'=>$model, 'acccategory'=>$acccategory,'job'=>$job)); ?> 

<?php $this->renderPartial('_listing',array('model' => $model,'arr_reviewer' => $arr_reviewer, 'current_reviewers'=> $current_reviewers),false,true); ?> 
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?> 

這是網格視圖 「_listing.php」

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'job-form', 
    'enableAjaxValidation'=>true, 
)); ?> 

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'acc-recei-grid', 
    'dataProvider'=>$model->search_reviewerlist(), 
    'filter'=>$model, 
    'columns'=>array(
     array(
      'class' => 'CCheckBoxColumn', 
      'selectableRows' => 2, 
      'checkBoxHtmlOptions' => array(
       'name' => 'userids[]', 
      ), 
      'value'=>'$data->id', 
      //'checked'=>'(in_array($data->id, $current_reviewers) ? 1 : ""', 
       'checked'=>function($data, $row) use ($current_reviewers){ 
       return in_array($data->id, $current_reviewers); 
       } 

     ), 
     'username', 
     array(
      'type'=>'raw', 
      'value'=>'$data->id', 
      //'filter'=>array('style'=>'visible:none'), 
      //'headerHtmlOptions'=>array('style'=>'width:0px; display:none; border:none; textdecoration:none'), 
      'htmlOptions'=>array('style'=>'display:none; border:none;', 'class'=>'user-id'), 
      //'header'=>false, 
      //'filter'=>false, 
     ), 

    ), 
)); ?> 


<div align="center"> 
     <?php echo CHtml::ajaxSubmitButton(Yii::t('reviewer','Update'),Yii::app()->createUrl('implementer/updatereviewer',array('id'=>$model->id)),array('success'=>'js: function(data) { 

         $("#reviewerlist").dialog("close"); 
        }'),array('id'=>'closeJobDialog')); ?> 


    </div> 

<?php $this->endWidget(); ?> 

這是我的控制器功能來獲取複選框的值

public function actionUpdatereviewer() 
    { 
     var_dump($_POST['userids']); 
     echo 'debug'; 
     echo $_GET['id']; 
     die;  

    } 

謝謝您的任何建議。

+0

這是我不知道的東西 –

回答

0

我自己得到了它

這是我的觀點

<div style="height:50px;">  
     <?php $imghtml=CHtml::image(Yii::app()->request->baseUrl.'/images/assets/approver.png','', array('style'=>'margin: 5px 0;')); ?> 
      <?php echo CHtml::ajaxLink(
        Yii::t('customer_id',$imghtml), 
        $this->createUrl('implementer/approverlist', array('id'=>$model->id)), 
        array(
         'onclick'=>'$("#reviewerlist").dialog("open"); return false;', 
         'update'=>'#reviewerlist' 
         ), 
        array('id'=>'reviewer-link', 
          'class'=>'btn btn-info', 
          'title'=>'Add/Remove reviewer', 
          'style'=>'width:25px; float:right; margin-button:20px;',) 
        );?> 
       <div id="reviewerlist"></div> 
     </div> 

這是_list.php(從彈出框中呈現爲我的問題)

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'job-form', 
    'enableAjaxValidation'=>true, 
)); ?> 

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'acc-recei-grid', 
    'dataProvider'=>$model->search_reviewerlist(), 
    'filter'=>$model, 
    'columns'=>array(
     array(
      'class' => 'CCheckBoxColumn', 
      'selectableRows' => 2, 
      'checkBoxHtmlOptions' => array(
       'name' => 'userids[]', 
      ), 
      'value'=>'$data->id',   
      'checked'=>function($data, $row) use ($current_reviewers){ 
       return in_array($data->id, $current_reviewers); 
      }    
     ), 
     'username', 

    ), 
)); ?> 


<div align="center"> 
     <?php echo CHtml::ajaxSubmitButton(Yii::t('reviewer','Update'),Yii::app()->createUrl('implementer/updatereviewer',array('id'=>$model->id)),array('success'=>'js: function(data) { 

         $("#reviewerlist").dialog("close"); 
        }'),array('id'=>'closeJobDialog')); ?> 
    </div> 
<?php $this->endWidget(); ?> 

這是我的控制器

public function actionApproverlist($id) 
    { 
     $users = new Users('reviewerlist'); 
     //$users->scenario = "reviewerlist"; 
     $users->unsetAttributes(); // clear any default values 

     if(isset($_GET['Users'])) 
      $users->attributes=$_GET['Users']; 


     $model    = $this->loadModel($id); 
     $arr_reviewer   = Users::model()->get_reviewers(); 

     $current_reviewers = explode(',', $model->reviewers); 
     $reviewer_lastcomment = Yii::app()->generals->last_comment($model, $current_reviewers); 

     $this->renderPartial('listing',array('model' => $users, 'arr_reviewer' => $arr_reviewer, 'current_reviewers'=> $current_reviewers),false,true); 

    } 

    public function actionUpdatereviewer() 
    { 
     var_dump($_POST['userids']); 

    } 

c在你的firebug->網絡上檢查$ _POST ['userids']。你會看到$ _POST ['userids']的值。

讓我們一起跳舞吧。 Cheeer!