Yii:使 dropDownList 在表单中只读/禁用

ers*_*sks 2 php yii

我正在尝试DropDownList在表单中设置只读或禁用更新条件,但我的代码无法正常工作...

echo $form->dropDownListRow($model, 'sem_id', CHtml::listData(Sem::model()->findAll(), 'id', 'title'/*, array("disabled" => "disabled")*/ , array('readonly' => 'readonly') ));
Run Code Online (Sandbox Code Playgroud)

错误:call_user_func() 期望参数 1 是有效的回调,数组必须恰好有两个成员

ham*_*med 5

首先,你应该dropDownList而不是dropDownListRow. 另外你忘了使用)after'title'并且你应该使用"disabled" => "disabled"而不是'readonly' => 'readonly'. 我不认为他们在 html 标签中有只读属性。

echo $form->dropDownList($model, 'sem_id', CHtml::listData(Sem::model()->findAll(), 'id', 'title'), array("disabled" => "disabled"));
Run Code Online (Sandbox Code Playgroud)

这可以禁用下拉列表,但请注意,您不能中继 html 属性。因为用户可以轻松删除此属性并可以更改下拉值。所以你需要对你的服务器进行控制。