flsy0918 2016-05-19 11:12:10 8297次浏览 3条评论 5 3 0
<?= $form->field($model, 'xxxx')->dropDownList(['1' => '天堂', '2' => '地狱', '3' => '人间', '4' => '其他'],['prompt'=>'请选择','class'=>"form-control",'options'=>['3'=>['Selected'=>true]]])->label(false) ?>

当然也有人直接在上面加上 $model->xxxx = N;也能设置默认值的

觉得很赞
  • 评论于 2016-05-21 12:16 举报

    怎么没人回复我

  • 评论于 2016-07-06 14:38 举报
    public static function dropDownList($name, $selection = null, $items = [], $options = [])
        {
            if (!empty($options['multiple'])) {
                return static::listBox($name, $selection, $items, $options);
            }
            $options['name'] = $name;
            unset($options['unselect']);
            $selectOptions = static::renderSelectOptions($selection, $items, $options);
            return static::tag('select', "\n" . $selectOptions . "\n", $options);
        }
    

    看手册上的说明就可以知道,第一个参数-input的名称,第二个参数-默认值,第三个就是选项数组了,第四个...还是看文档吧
    这个方式也可以吧。

  • 评论于 2017-11-09 16:25 举报

    yii\helpers\baseHtml 这个方法renderSelectOptions 大约是1753行18.png

您需要登录后才可以评论。登录 | 立即注册