gpt4 book ai didi

php - 如何从cgridview 中获取复选框的值?

转载 作者:搜寻专家 更新时间:2023-10-31 22:11:01 26 4
gpt4 key购买 nike

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

状态:我使用 CJuiDialog 在弹出框中创建了 cgridview。但是我无法从 GridView 中获取复选框的值。我收到 500 错误。

这是我打开弹框的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('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');?>

这是 GridView “_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(); ?>

这是我的 Controller 函数,用于获取复选框的值

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

}

感谢您的任何建议。

最佳答案

我自己找的

这是我的看法

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

这是我的 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']);

}

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

与 yii 共舞。加油!!!

关于php - 如何从cgridview 中获取复选框的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13024184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com