Yii生成下拉列表主要用到了CHtml类 里面的两个静态方法listData和dropDownList。

listData接收四个参数

  1. array $model  指的是我们从数据库查询的记录结果。
  2. string $valueField  指的是下拉列表option  value属性的值。
  3. string $textField 指的是下拉列表所显示的文本内容。
  4. string $groupField 是一个可选参数, 指的是 下拉列表分组optgroup label的值。

dropDownList接收四个参数

  1. string $name 指的是下拉列表的 name的值。
  2. string $selected 指的是默认选中的值 option  selected="selected".
  3. array $data  是listData的返回值。
  4. array $htmlOptions 指的是其他的html 属性。

另外 CActiveForm 里面也有个dropDownList , 该方法和CHtml 里面的dropDownList方法所接收参数略有不同,但是和CHtml里面的 activeDropDownList的参数相同。

  1. CModel $model 指的是一个模型的实例。
  2. string $attribute 指的是下拉列表 name的值。
  3. array $data 是listData的返回值。
  4. array $htmlOptions 指的是其他的html的属性。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-12-04
  • 2021-11-09
  • 2021-10-22
猜你喜欢
  • 2022-12-23
  • 2021-09-01
  • 2022-01-09
  • 2022-12-23
  • 2021-05-23
  • 2021-09-21
  • 2022-12-23
相关资源
相似解决方案