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

相关推荐
maxmaxma11 分钟前
ROS2机器人少年创客营:Python第三课
开发语言·python·机器人·ros2
J2虾虾35 分钟前
Java使用jcifs读取Windows的共享文件
java·开发语言·windows
421!1 小时前
C 语言学习笔记——11(函数指针与指针函数)
c语言·开发语言·笔记·单片机·学习
cch89181 小时前
汇编与C语言:底层对话VS高效指挥
c语言·开发语言·汇编
♪-Interpretation1 小时前
第七节:Python的内置容器
开发语言·python
551只玄猫1 小时前
【数学建模 matlab 实验报告8】回归分析
开发语言·数学建模·matlab·课程设计·实验报告
liulilittle1 小时前
OPENPPP2 1.0.0.26145 正式版发布:内核态 SYSNAT 性能飞跃 + Windows 平台避坑指南
开发语言·网络·c++·windows·通信·vrrp
lingggggaaaa2 小时前
PHP原生开发篇&SQL注入&数据库监控&正则搜索&文件定位&静态分析
数据库·sql·安全·web安全·php
消失的旧时光-19432 小时前
C++ 网络服务端主线:从线程池到 Reactor 的完整路线图
开发语言·网络·c++·线程池·并发