问:如何从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']);
}
在你的firebug-&gt;网络上检查$ _POST ['userids']。你会看到$ _POST ['userids']的价值。
和yii一起跳舞吧。 Cheeer !!!