下拉框数据生成
-
模型里选择数据
public static function getTypeList() { $list=self::where(true)->select(); $res=[]; foreach ($list as $k=>$v){ $res[$v['id']]=$v['name']; } return $res; }
-
控制器的渲染数据
public function _initialize() { parent::_initialize(); $this->model = new appadminmodelyuyueSchedule; $this->view->assign("TypeList", NewchatType::getTypeList()); }
-
html里显示数据
<div class="form-group"> <label class="control-label col-xs-12 col-sm-2">{:__('Typeid')}:</label> <div class="col-xs-12 col-sm-8"> <select id="c-typeid" data-rule="required" class="form-control selectpicker" name="row[typeid]"> {foreach name="TypeList" item="vo"} <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option> {/foreach} </select> </div> </div>