新聞動態

                                                                                  位置:首頁 新聞動態 常見問題

                                                                                  襄陽網站建設分享:thinkphp6 Auth權限管控

                                                                                  新聞動態
                                                                                  2020年06月23日 閱讀:2903次

                                                                                  Auth安裝地址

                                                                                  //thinkphp5.1
                                                                                  composer require liliuwei/thinkphp-auth=1.0.*
                                                                                  //thinkphp6.0
                                                                                  composer require liliuwei/thinkphp-auth=2.0.*

                                                                                  1.調用

                                                                                  use liliuwei\think\Auth;

                                                                                  2.獲取控制器

                                                                                  $request=\think\facade\Request::instance();
                                                                                   $root=$this->request->root();
                                                                                   $con=$this->request->controller();
                                                                                   $action = $this->request->action();
                                                                                   $name=$root.'/'.$con.'/'.$action;

                                                                                  3.實例化 Auth

                                                                                   $auth=new Auth();

                                                                                  4.使用Auth判斷控制器是否有權限

                                                                                  if (session('id')!=1 && $name!="/admin/Index/index" && $name!="/admin/Index/welcome" && $name!="admin/Admin/logout"){  
                                                                                    if (!$auth->check($name,session('id'))){  
                                                                                          echo "";    
                                                                                     }
                                                                                  }

                                                                                  上一篇

                                                                                  下一篇

                                                                                  關鍵詞: 襄陽網站建
                                                                                  亚洲中文字幕在线19页_99久久国产精品免费热7788_欧美专区日韩专区综合专区_小泽玛利亚一区_gogo999亚洲肉体艺术