欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > thinkphp 多选框

thinkphp 多选框

2025/2/22 2:10:39 来源:https://blog.csdn.net/weixin_40367377/article/details/144631154  浏览:    关键词:thinkphp 多选框

视图

             <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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词