3

问:如何从 cgridview 中获取复选框值?

状态:我使用 CJuiDialog 在弹出框中创建 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;    

    }

感谢您的任何建议。

4

1 回答 1

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

    }

在你的 firebug->network 中检查 $_POST['userids']。您将看到 $_POST['userids'] 的值。

和 yii 一起跳舞吧。加油!!!

于 2012-10-23T09:56:10.397 回答