当前位置: 首页 > article >正文

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


http://www.kler.cn/a/447899.html

相关文章:

  • < Chrome Extension : TamperMonkey > 去禁用网页的鼠标的事件 (水文)
  • Pytorch | 利用MI-FGSM针对CIFAR10上的ResNet分类器进行对抗攻击
  • 浅析InnoDB引擎架构(已完结)
  • Leetcode 37 Sudoku Solver
  • FastJSON 默认不会包含值为 null 的字段
  • C 语言实现四旋翼飞行器姿态控制:基于 PID 控制器(2)
  • 【前端js】 indexedDB Nosql的使用方法
  • Sourcegraph 概述
  • Redis篇--常见问题篇8--缓存一致性3(注解式缓存Spring Cache)
  • opencv项目--文档扫描
  • 3.metagpt中的软件公司智能体 (Architect 角色)
  • 纯血鸿蒙APP实战开发——文字展开收起案例
  • C# cad启动自动加载启动插件、类库编译 多个dll合并为一个
  • 图解HTTP-HTTP协议
  • 反归一化 from sklearn.preprocessing import MinMaxScaler
  • 2024年最新多目标优化算法:多目标麋鹿群优化算法(MOEHO)求解DTLZ1-DTLZ7及工程应用---盘式制动器设计,提供完整MATLAB代码
  • iframe和浏览器页签切换
  • 解决uniapp中使用axios在真机和模拟器下请求报错问题
  • 亚马逊API接口深度解析:如何高效获取商品详情与评论数据
  • 洛谷 P1644 跳马问题 C语言