<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                表單器中新增加 與 修改是類似的,他們都要用到類的屬性 `protected $form_items;` 沒有使用函數的話,就可以直接在屬性中附值,比如 ~~~ protected $form_items = [ ['text', 'title', '標題'], ['text', 'keywords', 'SEO關鍵字'], ['text', 'descrip', '分享描述'], ['jcrop', 'picurl', '分享圖片'], ['text', 'template', '模板路徑','路徑要包含風格名,只能放在index_style目錄下,比如:“qiboxx/index/alonepage/pc_index.htm”'], ['radio', 'status', '是否啟用', '', [1 => '啟用', 0 => '禁用'], 1], ['ueditor', 'content', '內容'], ]; ~~~ 如果涉及到函數的話,就需要在方法里邊賦值,如下: ~~~ $this->form_items = [ ['select','fid', '所屬分類', '',getsort()], //因為getsort()是函數,只能在方法里邊定義 ['text','name', '插件名稱', ''], ['static','keywords', '插件關鍵字', ''], ['radio','ifopen', '啟用或禁用', '',['關閉系統','啟用系統']], ['textarea','about', '介紹', ''], ['number','list', '排序值', ''], ['icon','icon', '圖標', ''], ]; ~~~ 文件中 `\application\common\traits\AddEditList.php` 的 `add()` `edit()` 這兩個方法僅只是示范. ~~~ public function add() { return $this -> addContent(); } public function edit($id = null) { if (empty($id)) $this -> error('缺少參數'); $info = $this -> getInfoData($id); return $this -> editContent($info); } ~~~ add()方法中的核心是addContent()方法,我們來看看他的代碼 ~~~ protected function addContent($url = 'index', $vars = []) { // 保存數據 if ($this -> request -> isPost()) { if ($this -> saveAddContent()) { $this -> success('添加成功', $url); } else { $this -> error('添加失敗'); } } $template = $this->get_template('',$this->mid); //如果模板存在的話,就用實際的后臺模板 if (empty($template)) { $template = $this->get_template('admin@common/wn_form'); } $this->assign('mid',$this->mid); $this->assign('f_array',$this -> form_items); $this->assign('tab_ext',$this->tab_ext); return $this->fetch($template,$vars); } ~~~ 里邊包含了表單的顯示與數據的處理 ***** add() edit() 這兩個方法, 還是推薦大家重寫, 這樣代碼的可讀性會更好些. 重寫 add() 方法的原因,有3種情況, 一種是對POST提交數據重新做處理, 另一種是對顯示的表單數據做特殊處理, 最后一種,就同時需要對表單的顯示數據及提交數據都要做處理. 針對第一種情況,比較省事的做法,一般是按如下處理 ~~~ public function add() { if ($this->request->isPost()) { $data = $this->request->post(); if (!empty($this -> validate)) { //驗證數據 $result = $this -> validate($data, $this -> validate); if (true !== $result) $this -> error($result); } if($data['title']==''){ $this->error('用戶組名稱不能為空!'); } if(GroupModel::create($data)){ $this->success('創建成功 ', url('index') ); } else { $this->error('創建失敗'); } } return $this -> addContent(); } ~~~ 即在 `return $this -> addContent();` 的前面劫持掉POST數據,終斷下面的操作 針對第二種情況,比較省事的做法,一般是按如下處理 ~~~ public function add(){ $this->tab_ext['page_title'] = '添加充值卡'; $this->form_items = [ //['money','rmb','充值卡面額'], ['number','money','充值卡積分個數'], ['radio','sncode_type','充值卡密碼復雜度','',['純數字','純字母','數字+字母'],2], ['number','sncode_leng','密碼長度'], ['number','num','批量生成多少個'], ]; return $this->addContent(); } ~~~ 即在 `return $this -> addContent();` 的前面添加表單參數.如果參數沒用到函數的話, 可以直接在類的屬性又或者是 `_initialize()` 初始化類的方法里邊定義也是一樣的 第三種情況,就是同時要修改表單屬性與處理提交數據的時候,可以參考下面的 ~~~ public function add(){ if ($this -> request -> isPost()) { $data = $this->request->post(); if ($data['money']<1&&$data['rmb']<1) { $this->error('面額不能小于1'); } $ck = 0; for ($i=0;$i<$data['num'];$i++){ if ($this -> model -> create($data)) { $ck++; } } if ($ck) { $this->success('操作成功','index'); }else{ $this->error('生成失敗,請重新生成一次'); } } $this->tab_ext['page_title'] = '批量生成充值卡'; $this->form_items = [ //['money','rmb','充值卡面額'], ['number','money','充值卡積分個數'], ['radio','sncode_type','充值卡密碼復雜度','',['純數字','純字母','數字+字母'],2], ['number','sncode_leng','密碼長度'], ['number','num','批量生成多少個'], ]; return $this->addContent(); } ~~~ 修改其實跟新增是差不多的.這里不重復了!!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看