<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 知識點: 1、準備工作 2、添加規則 3、規則排序 4、規則刪除 5、編輯規則 [TOC] ## 一、準備工作 ### 1、build建Authrule模型 簡單 ### 2、引入類庫 use think\Controller; use think\Db; use util\Tree; use app\admin\model\Authrule as AuthruleModel; ### 3、操作 ~~~ class Authrule extends Common { public function index($tab = 1, $id = 0){ $authruleArray = AuthruleModel::order('id')->select(); foreach ($authruleArray as $key => $value) { $authruleList[] = $value->toArray(); //對象轉數組 } $tree = new Tree(); $tree->tree($authruleList,'id','pid','title'); $authrule = $tree->getArray(); $this->assign('authrule',$authrule); return view(); } } ~~~ ### 4、數據表不存在 解決方法 use think\Model; ~~~ class Authrule extends Model { //當前模型對應的數據表名 protected $table = 'sfox_auth_rule'; } ~~~ ### 5、樹型菜單 ~~~ use util\Tree; $authruleArray = AuthruleModel::order('id')->select(); foreach ($authruleArray as $key => $value) { $authruleList[] = $value->toArray(); //對象轉數組 } $tree = new Tree(); $tree->tree($authruleList,'id','pid','title'); $authrule = $tree->getArray(); $this->assign('authrule',$authrule); ~~~ tree有四個參數 參一:數組 參二:當前ID 參三:父ID 參數:中文名稱 ### 6、模型 ~~~ <?php namespace app\admin\model; use think\Model; class Authrule extends Model { //當前模型對應的數據表名 protected $table = 'sfox_auth_rule'; } ~~~ ### 7、新增pid、child、listorder字段 pid 父ID,默認值0,無符號 child 是否子孫,tinyint 長度1,默認值0,無符號 listorder 排序smallint,默認值0,無符號 ## 二、添加規則 ### 1、模板 片段: ~~~ <option value="{$vo.id}" {$vo.id ? '' : 'disabled'} {if condition="input('pid',0) eq $vo.id"}selected{/if}>{$vo.title}</option> ~~~ ~~~ <div class="form-group"> <label class="col-sm-2 control-label">上級規則</label> <div class="col-sm-10"> <select class="form-control m-b" name="pid"> <option value="0" selected>≡ 頂級 ≡</option> {volist name="authrule" id="vo"} <option value="{$vo.id}" {$vo.id ? '' : 'disabled'} {if condition="input('pid',0) eq $vo.id"}selected{/if}>{$vo.title}</option> {/volist} </select> </div> </div> ~~~ ### 2、添加 ~~~ public function add($tab = 1){ if(request()->isPost()){ $authruleModel = new AuthruleModel; if($authruleModel->allowField(true)->save(input('post.'))){ return success('新規則添加成功!',url('index',['tab'=>1])); }else{ return error('規則添加失敗!',url('index',['tab'=>$tab])); } } } ~~~ ## 三、規則排序 ~~~ public function index($tab = 1, $id = 0){ if(request()->isPost()){ foreach (input('post.listorder/a') as $key => $value) { Db::name('auth_rule')->where('id',$key)->update(['listorder'=>$value]); } return success('排序更新成功!',url('index',['tab'=>$tab])); }else{ $authruleArray = AuthruleModel::order('id')->select(); foreach ($authruleArray as $key => $value) { $authruleList[] = $value->toArray(); //對象轉數組 } $tree = new Tree(); $tree->tree($authruleList,'id','pid','title'); $authrule = $tree->getArray(); $this->assign('authrule',$authrule); // 編輯規則 if( 3 == $tab ){ // 獲取所要編輯菜單的信息 $info = Db::name('auth_rule')->where('id',$id)->find(); if($info!=null && is_array($info)){ $this->assign('info',$info); } } } return view(); } ~~~ ## 四、規則刪除 ~~~ public function delete($id = 0){ if(Db::name('auth_rule')->where('id', $id)->delete()){ return success('刪除成功!',url('index',['tab'=>1])); }else{ return error('刪除失敗!',url('index',['tab'=>1])); } } ~~~ ## 五、編輯規則 ### 1、獲取所要編輯菜單的信息 ~~~ public function index($tab = 1, $id = 0){ if(request()->isPost()){ foreach (input('post.listorder/a') as $key => $value) { Db::name('auth_rule')->where('id',$key)->update(['listorder'=>$value]); } return success('排序更新成功!',url('index',['tab'=>$tab])); }else{ $authruleArray = AuthruleModel::order('id')->select(); foreach ($authruleArray as $key => $value) { $authruleList[] = $value->toArray(); //對象轉數組 } $tree = new Tree(); $tree->tree($authruleList,'id','pid','title'); $authrule = $tree->getArray(); $this->assign('authrule',$authrule); // 編輯規則 if( 3 == $tab ){ // 獲取所要編輯菜單的信息 $info = Db::name('auth_rule')->where('id',$id)->find(); if($info!=null && is_array($info)){ $this->assign('info',$info); } } } return view(); } ~~~ ### 2、編輯操作 ~~~ public function edit($tab = 1, $id = 0){ if(request()->isPost()){ $authrule_form = input('post.'); //判斷child狀態 if(input('post.child')==null){ $authrule_form['child'] = 0; $count = Db::name('auth_rule')->where('pid',$id)->count(); if($count){ return error('該規則擁有子項,無法取消勾選!'); } } // 編輯規則 $authruleModel = new AuthruleModel; if($authruleModel->allowField(true)->isUpdate()->save($authrule_form)){ return success('規則編輯成功!',url('index',['tab'=>1])); }else{ return error('規則信息未修改或編輯失敗!'); } } } ~~~
                  <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>

                              哎呀哎呀视频在线观看