【发布时间】:2023-03-10 04:08:01
【问题描述】:
我想在我的 Seachmodel 中实现一个 checkBoxList,但没有找到好的解决方案。我怎样才能做到这一点?在我的模型中,我有一个值数组:
型号:
const ART_BLACK = 10;
const ART_GREEN = 20;
const ART_ORANGE = 30;
public static function colorText() {
return [
self::ART_BLACK => 'Black',
self::ART_GREEN => 'Green',
self::ART_ORANGE => 'Orange',
];
}
搜索视图(_search)
<?= $form->field($model, 'color[]')->checkboxList(Color::colorText()); ?>
执行搜索后,不再选择所有元素。我也可以将带有值的数组放在 SearchModel 中,但仍然不知道最好保存它们以在搜索后再次显示。
【问题讨论】:
标签: yii2 checkboxlist