好吧,讓我們把單選按鈕,而不是所有的下拉哈哈。 我假設你有你的觀點成立這樣的:
// view/index.php (or similar)
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>Message::model(),
'columns'=>
[
'id',
'username',
'email:email',
'approved'=>[
'name'=>'approved',
'filter'=>$this->approvedFilter(),
// I like moving stuff like this out of the way.
// But maybe it's smarter to put it in your model instead?
]
]
));
接下來的控制器。
// MessageController.php (or similar)
public function actionIndex()
{
$model = Message::model();
// All we need to do is to assign the incoming value to the model we are using...
if (isset($_GET['Message']['Approved'])){
$model->approved = $_GET['Message']['Approved'];
}
$this->render('index', ['model'=>$model]);
}
// Oh yeah the filter. I just copied your code.
public function approvedFilter(){
return CHtml::activeRadioButtonList(
Message::model(), 'approved', array(0,1),
array(
'labelOptions'=>array('style'=>'display:inline'),
'separator'=>''
)
);
}
此代碼已經過測試,但我做了一些最後一分鐘的變化,很抱歉,如果它吹起來! 而我仍然認爲一個簡單的「批准:布爾」更清潔。 ;)