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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## **路由中間件** 可以使用路由中間件,注冊方式如下: ~~~ Route::rule('hello/:name','hello') ->middleware(\app\middleware\Auth::class); ~~~ 或者對路由分組注冊中間件 ~~~ Route::group('hello', function(){ Route::rule('hello/:name','hello'); })->middleware(\app\middleware\Auth::class); ~~~ 如果需要傳入額外參數給中間件,可以使用 ~~~ Route::rule('hello/:name','hello') ->middleware(\app\middleware\Auth::class,'admin'); ~~~ 如果需要定義多個中間件,使用數組方式 ~~~ Route::rule('hello/:name','hello') ->middleware([\app\middleware\Auth::class,\app\middleware\Check::class]); ~~~ 可以統一傳入同一個額外參數 ~~~ Route::rule('hello/:name','hello') ->middleware([\app\middleware\Auth::class, \app\middleware\Check::class], 'admin'); ~~~ ## **示例** 1、新建控制器app\index\controller\Test.php ``` namespace app\index\controller; use app\BaseController; class Test extends BaseController { public function hello() { return 'hello'; } } ``` 2、 在app\index\route\route.php路由文件中將hello路由到該控制器的hello方法 ``` use think\facade\Route; Route::rule('hello','test/hello','GET') ->middleware([\app\index\middleware\Test::class]); ``` 3、在app\middleware.php文件中配置路由中間件 >[danger] 配置路由中間件在上一步的路由文件中就配置了,所以步驟3這一步是多余的 > 在路由文件中使用middleware方法配置中間件的好處是可以針對控制器的某個路由方法,而不是整個index模塊 > 如果在魯豫文件中少了`->middleware([\app\index\middleware\Test::class]);`這一步則需要這一步 ``` // 全局中間件定義文件 return [ // 全局請求緩存 // \think\middleware\CheckRequestCache::class, // 多語言加載 // \think\middleware\LoadLangPack::class, // Session初始化 // \think\middleware\SessionInit::class app\index\middleware\Test::class, ]; ``` 4、新建路由中間件app\index\middleware\Test.php ``` namespace app\index\middleware; class Test { public function handle($request, \Closure $next) { if ($request->param('name') == 'think') { return redirect('index/think'); } return $next($request); } } ``` 更多中間件的用法參考架構章節的[中間件](http://www.hmoore.net/manual/thinkphp6_0/1037493)內容。
                  <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>

                              哎呀哎呀视频在线观看