Checkbox Yii CGridView和每行多个复选框
背景 我有一个包含多个复选框列的CGridView。我使用如下代码创建了复选框列:Checkbox Yii CGridView和每行多个复选框,checkbox,controller,yii,Checkbox,Controller,Yii,背景 我有一个包含多个复选框列的CGridView。我使用如下代码创建了复选框列: $columns[] = array( 'header'=>'Health', 'value' => 'CHtml::checkBox("hsid[]", $data->healthService, array("value"=>$data->wc_client_id,"id"=>"hsid_".$data->wc_client_id))', 't
$columns[] = array(
'header'=>'Health',
'value' => 'CHtml::checkBox("hsid[]", $data->healthService, array("value"=>$data->wc_client_id,"id"=>"hsid_".$data->wc_client_id))',
'type'=>'raw',
'htmlOptions'=>array('style'=>'text-align:center'),
);
$columns[] = array(
'header'=>'Education',
'value' => 'CHtml::checkBox("esid[]", $data->educationService, array("value"=>$data->wc_client_id,"id"=>"esid_".$data->wc_client_id))',
'type'=>'raw',
'htmlOptions'=>array('style'=>'text-align:center'),
);
$data->healthService和$data->educationService用于根据数据库中的数据设置复选框的初始选中状态
问题
如何捕获对一行中每个不同复选框的更改,并将这些更改发送回控制器?然后,控制器将根据复选框的更改来更新数据库。更好的选择是
CCheckBoxColumn
请看以下是我最终如何让它工作的: 查看代码
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'service-grid',
'dataProvider'=>$clients->search(),
'columns'=>array(
'first_name',
'last_name',
array(
'header'=>'Education',
'class'=>'CDataColumn',
'type'=>'raw',
'htmlOptions'=>array('style'=>'text-align:center'),
'value' => 'CHtml::checkBox("esid[]", $data->education, array("value"=>$data->wc_client_id,"id"=>"esid_".$data->wc_client_id))',
),
array(
'header'=>'Health',
'class'=>'CDataColumn',
'type'=>'raw',
'htmlOptions'=>array('style'=>'text-align:center'),
'value' => 'CHtml::checkBox("hsid[]", $data->health, array("value"=>$data->wc_client_id,"id"=>"hsid_".$data->wc_client_id))',
)
),
));
用于检索所选ID的控制器代码
$healthClientId = array();
if(isset($_POST['hsid']) && is_array($_POST['hsid']))
{
$healthClientId = $_POST['hsid'];
}
$educationClientId = array();
if(isset($_POST['esid']) && is_array($_POST['esid']))
{
$educationClientId = $_POST['esid'];
}
v2p,我尝试使用CCheckBoxColumn,但无法控制列标题。当selectableRows>=2时,列标题强制为复选框。我需要列标题来指示复选框表示的服务类型。