<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之旅 廣告
                # 路由分組 ## 路由分組 路由分組功能允許把相同前綴的路由定義合并分組,這樣可以簡化路由定義,并且提高路由匹配的效率,不必每次都去遍歷完整的路由規則(尤其是開啟了路由延遲解析后性能更佳)。 使用`Route`類的`group`方法進行注冊,給分組路由定義一些公用的路由設置參數,使用規范如下: > #### Route::group('分組名(字符串)或者分組路由參數(數組)','分組路由規則(數組或者閉包)'); 其中路由參數和變量規則為可選,同樣建議使用方法進行參數設置。 例如: ``` Route::group('blog', [ ':id' => 'Blog/read', ':name' => 'Blog/read', ])->ext('html')->pattern(['id' => '\d+']); ``` 支持使用閉包方式注冊路由分組,例如: ``` Route::group('blog', function () { Route::rule(':id', 'blog/read'); Route::rule(':name', 'blog/read'); })->ext('html')->pattern(['id' => '\d+', 'name' => '\w+']); ``` 如果僅僅是用于對一些路由規則設置一些公共的路由參數,也可以使用: ``` Route::group(['method' => 'get', 'ext' => 'html'], function () { Route::rule('blog/:id', 'blog/read'); Route::rule('blog/:name', 'blog/read'); })->pattern(['id' => '\d+', 'name' => '\w+']); ``` 路由分組支持嵌套,例如: ``` Route::group(['method' => 'get', 'ext' => 'html'], function () { Route::group('blog', function () { Route::rule('blog/:id', 'blog/read'); Route::rule('blog/:name', 'blog/read'); }); })->pattern(['id' => '\d+', 'name' => '\w+']); ``` > 如果使用了嵌套分組的情況,子分組會繼承父分組的參數和變量規則,而最終的路由規則里面定義的參數和變量規則為最優先。 可以使用`prefix`方法簡化相同路由地址的定義,例如下面的定義 ``` Route::group('blog', function () { Route::get(':id', 'blog/read'); Route::post(':id', 'blog/update'); Route::delete(':id', 'blog/delete'); })->ext('html')->pattern(['id' => '\d+']); ``` 可以簡化為 ``` Route::group('blog', function () { Route::get(':id', 'read'); Route::post(':id', 'update'); Route::delete(':id', 'delete'); })->prefix('blog/')->ext('html')->pattern(['id' => '\d+']); ``` ## 延遲路由解析 新版路由支持延遲路由解析,也就是說你定義的路由規則(主要是分組路由和域名路由規則)在加載路由定義文件的時候并沒有實際注冊,而是在匹配到路由分組或者域名的情況下,才會實際進行注冊和解析,大大提高了路由注冊和解析的性能。 默認是關閉延遲路由解析的,你可以在應用的`app.php`配置文件中設置: ``` // 開啟路由延遲解析 'url_lazy_route' => true, ``` 開啟延遲路由解析后,如果你需要生成路由反解URL,需要使用命令行指令 ``` php think optimize:route ``` 來生成路由緩存解析。 ## 傳入額外參數 可以統一給分組路由傳入額外的參數 ``` Route::group('blog', [ ':id' => 'Blog/read', ':name' => 'Blog/read', ])->ext('html') ->pattern(['id' => '\d+']) ->append(['group_id'=>1]); ``` 上面的分組路由統一傳入了`group_id`參數,該參數的值可以通過`Request`類的`param`方法獲取。
                  <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>

                              哎呀哎呀视频在线观看