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

相关推荐
hogenlaw12 分钟前
Stream流
android·java·开发语言
ShCDNay22 分钟前
Python核心底层知识(个人记录)
开发语言·python
xyq202432 分钟前
组合实体模式
开发语言
来自远方的老作者34 分钟前
第7章 运算符-7.2 赋值运算符
开发语言·数据结构·python·赋值运算符
A.A呐35 分钟前
【C++第二十四章】异常
开发语言·c++
常利兵1 小时前
解锁Kotlin:数据类与密封类的奇妙之旅
android·开发语言·kotlin
来自远方的老作者1 小时前
第7章 运算符-7.1 算术运算符
开发语言·数据结构·python·算法·算术运算符
MwEUwQ3Gx1 小时前
PHP 异步与多线程 从 TrueAsync 展望未来
开发语言·php
不会写DN1 小时前
Go中如何跨语言实现传输? - GRPC
开发语言·qt·golang
她说..2 小时前
Java 基本数据类型高频面试题
java·开发语言·jvm·spring boot