我想在发布更新时检查Yii2 CheckboxList我的选项列表如下所述
= $form->field($category,'title')->checkboxList([1=>'Latest news','2'=>'Unit Performance','3'=>'Latest Technology'])->label(FALSE); ?>
我想检查在创建帖子时选择的更新时的某个项目like latest news
.
请帮助我
使用示例代码行.
$list = [1=>'Latest news','2'=>'Unit Performance','3'=>'Latest Technology']; = $form->field($category,'title')->checkboxList($list)->label(FALSE); ?>
如果选择"最新消息"和"单位性能"选项,则更新时选择的选项值数组将为 $checkedList = [1, 2];
所以,只需将$checkedList
数组分配给$category->title
.像,
$category->title = $checkedList;
完整的例子是:
$list = [1=>'Latest news','2'=>'Unit Performance','3'=>'Latest Technology']; if(!$category->isNewRecord) { $checkedList = [1, 2]; //get selected value from db if value exist $category->title = $checkedList; } = $form->field($category,'title')->checkboxList($list)->label(FALSE); ?>