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

相关推荐
叫我一声阿雷吧9 分钟前
JS 入门通关手册(21):原型链:JS 继承的底层原理
开发语言·javascript·前端面试·原型链·js继承·js进阶·js面向对象
猫墨*15 分钟前
springboot3、knife4j-openapi3配置动态接口版本管理
java·开发语言
weixin_5316518116 分钟前
Python 渐进式学习指南
开发语言·windows·python
weixin_6495556718 分钟前
C语言程序设计第四版(何钦铭、颜晖)第八章指针之在数组中查找指定元素
c语言·开发语言
add45a22 分钟前
C++中的原型模式
开发语言·c++·算法
代码s贝多芬的音符22 分钟前
Android NV21 转 YUV 系列格式
android·开发语言·python
2401_8442213223 分钟前
C++类型推导(auto/decltype)
开发语言·c++·算法
2201_7538777923 分钟前
高性能计算中的C++优化
开发语言·c++·算法
无限进步_24 分钟前
深入解析C++容器适配器:stack、queue与deque的实现与应用
linux·开发语言·c++·windows·git·github·visual studio
2501_9454251524 分钟前
分布式系统容错设计
开发语言·c++·算法