Yii1.1 下拉列表中 htmloptions 的问题
我使用 Yii 1.1,我有一个关于下拉列表的问题。 除了选项标签中的经典值之外,我尝试设置一个额外的属性。
数据来自数据库的查询。
问题是我设法设置了额外的属性,但似乎第一个选项标签的额外属性没有显示。
这是我在视图部分中的代码:
$types_list = CHtml::listData($model->getTypesnewCodes(),'id','description');
$flg = $model->getTypesnewCodesflg();
$htmlOptions = array(
'prompt' => ("- Select an option -"),
'options' => $flg,
);
echo $form->labelEx($model, 'TypeId');
echo $form->dropDownList($model,'TypeId',$types_list, $htmlOptions);
这是我在模型中的代码:
public function getTypesnewCodesflg() {
$array =array();
$typesflg = Yii::app()->db->createCommand()
->select( 'id,flag')
->from('Types')
->queryAll();
array_push($array, $typesflg );
return $array[0];
}
I use Yii 1.1 and I have a question for the dropdownlist.
I try to set an extra attribute besides the classic value in the options tags.
The data are coming with queries from the database.
The problem is that I manage to set the extra attribute but it seems that the extra attribute for the first options tag is not displayed.
Here is my code in the view part:
$types_list = CHtml::listData($model->getTypesnewCodes(),'id','description');
$flg = $model->getTypesnewCodesflg();
$htmlOptions = array(
'prompt' => ("- Select an option -"),
'options' => $flg,
);
echo $form->labelEx($model, 'TypeId');
echo $form->dropDownList($model,'TypeId',$types_list, $htmlOptions);
Here is my code in the model:
public function getTypesnewCodesflg() {
$array =array();
$typesflg = Yii::app()->db->createCommand()
->select( 'id,flag')
->from('Types')
->queryAll();
array_push($array, $typesflg );
return $array[0];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在数据库中。我有一张有五条记录的表。 id 的键值从 1 到 5,当我将 id 的键值从 0 更改为 4 时,它起作用了。
所以要小心 id 的声明!
我真的希望我能帮助别人!
The problem was in the database. I had a table with five records. The value of the id's keys were, from 1 to 5 and when I changed the id's keys value from 0 to 4 it worked.
So be careful with the declaration of the id's!
I really hope that I helped someone!