视图
<div class="form-group"><label for="c-flag" class="control-label col-xs-12 col-sm-2 col-md-4">{:__('Flag')}</label><div class="col-xs-12 col-sm-8 col-md-8"><!--@formatter:off--><select id="c-flag" class="form-control selectpicker" multiple="" name="row[flag][]">{foreach name="flagList" item="vo"}<option value="{$key}" data-subtext="{$key}" {in name="key" value="$row.flag" }selected{/in}>{$vo}</option>{/foreach}</select><!--@formatter:on--></div></div>
控制器
public function edit($ids = null){$row = $this->model->get($ids);if (!$row) {$this->error(__('No Results were found'));}$adminIds = $this->getDataLimitAdminIds();if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {$this->error(__('You have no permission'));}if (false === $this->request->isPost()) {$this->view->assign('row', $row);//添加的代码
$FlagList= Db::table('fa_aaa_package')->select();$dx=[];foreach ($FlagList as $key => $value){$dx[$value['id']]=$value['name'];}$this->view->assign("flagList", $dx);return $this->view->fetch();}$params = $this->request->post('row/a');if (empty($params)) {$this->error(__('Parameter %s can not be empty', ''));}$params = $this->preExcludeFields($params);$result = false;Db::startTrans();try {//是否采用模型验证if ($this->modelValidate) {$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;$row->validateFailException()->validate($validate);}//添加的代码$params['flag']=implode(',', $params['flag']);$result = $row->allowField(true)->save($params);Db::commit();} catch (ValidateException|PDOException|Exception $e) {Db::rollback();$this->error($e->getMessage());}if (false === $result) {$this->error(__('No rows were updated'));}$this->success();}
数据库 表添加字段flag