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>

控制器

php 复制代码
    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

相关推荐
张人玉15 分钟前
WPF布局控件(界面骨架核心)
开发语言·c#·wpf·布局控件
闲人编程21 分钟前
使用MLflow跟踪和管理你的机器学习实验
开发语言·人工智能·python·机器学习·ml·codecapsule
看兵马俑的程序员27 分钟前
RAG实现-本地PDF内容加载和切片
开发语言·python·pdf
专注前端30年29 分钟前
【JavaScript】reduce 方法的详解与实战
开发语言·前端·javascript
两个人的幸福online37 分钟前
php使用腾讯云服务
开发语言·php·腾讯云
无敌最俊朗@39 分钟前
C++ STL Deque 高频面试题与答案
开发语言·c++
清羽_ls1 小时前
bash 基础编程的核心语法
开发语言·bash
和编程干到底1 小时前
C++基础
开发语言·c++
Z_Xshan1 小时前
docker 容器web站点 中文文件名访问404问题
linux·开发语言·docker
kkkkk0211062 小时前
【Rust创作】Rust 错误处理:从 panic 到优雅控制
开发语言·算法·rust