dta38159 2012-10-23 05:41
浏览 120

如何从cgridview获取复选框值?

Q : how to get the checkbox value from cgridview?

Status : I create cgridview in a popbox with CJuiDialog. But I can't get the value of checkbox from grid view. I got 500 error.

This is my view to open the popup box

<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>

This is the popup box

<?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');?>

This is the grid view "_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(); ?>

This is my controller function to get the value of checkbox

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

    }

Thank you for your any advice.

  • 写回答

1条回答 默认 最新

  • dongrunying7537 2012-10-23 09:56
    关注

    I got it by Myself

    This my view

    <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>
    

    This is _list.php (render from popup box as my question)

     <?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(); ?>
    

    This is my controller

    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']);
    
        }
    

    check $_POST['userids'] at your firebug->network. you will see the value of $_POST['userids'].

    Let dance with yii. Cheeer!!!

    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏