<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 路由 (Fast Route) 使用經過改造后 [Fast-Route](https://github.com/nikic/FastRoute) 作為路由組件,改造后支持 Mix 系列的全部功能。 ## 組件 使用 [composer]([https://www.phpcomposer.com/](https://www.phpcomposer.com/)) 安裝: ~~~ composer require mix/fast-route ~~~ ## 依賴注入配置 - [manifest/beans/route.php](https://github.com/mix-php/mix-skeleton/blob/master/manifest/beans/route.php) ## 路由調用 路由類是在 StartCommand::class 中使用的,因此用戶可隨意修改執行邏輯,具體調用方式如下: ~~~ $routeDefinitionCallback = function (Mix\FastRoute\RouteCollector $collector) { $collector->get('/profile/{id:\d+}', [\App\Web\Controllers\ProfileController::class, 'index'], [\App\Web\Middleware\ActionMiddleware::class] ); }; $globalMiddleware = [\App\Web\Middleware\GlobalMiddleware::class]; $router = new \Mix\FastRoute\Router($routeDefinitionCallback, $globalMiddleware); $server = new \Mix\Http\Server\Server('0.0.0.0', 9502); $server->start($router); ~~~ ## 文件加載路由 除了上面的使用閉包加載路由,還可以選擇把閉包寫到一個或者多個文件中來拆分路由。 ~~~ // 路徑可以是單個文件,也可以是目錄 $path = sprintf('%s/routes/api.php', app()->basePath); $router = new \Mix\FastRoute\Router($path, $globalMiddleware); ~~~ - 也可以在依賴配置中注入路徑:[manifest/beans/route.php#L12](https://github.com/mix-php/mix-skeleton/blob/master/manifest/beans/route.php#L12) ## 路由規則 >[danger] 注意:Mix 并不支持 TP 那種默認路由規則 `http://yourdomain/Module/Controller/Action`,每個路由都需要自己去配置 該組件采用閉包的形式定義路由,例如: ~~~php function (Mix\FastRoute\RouteCollector $collector) { // 單個,支持 get | post | put | delete | patch | head | options $collector->get('/profile/{id:\d+}', [\App\Web\Controllers\ProfileController::class, 'index'], [\App\Web\Middleware\ActionMiddleware::class] ); // 全部 // >= v2.2.9 $collector->any('/profile/{id:\d+}', [\App\Web\Controllers\ProfileController::class, 'index'], [\App\Web\Middleware\ActionMiddleware::class] ); // 自定義多個 // >= v2.2.9 $collector->match(['GET', 'OPTIONS'], '/profile/{id:\d+}', [\App\Web\Controllers\ProfileController::class, 'index'], [\App\Web\Middleware\ActionMiddleware::class] ); // 使用閉包自定義執行控制器 $collector->match(['GET', 'OPTIONS'], '/profile/{id:\d+}', function (\Mix\Http\Message\ServerRequest $request, \Mix\Http\Message\Response $response) { return call_user_func([new \App\Web\Controllers\ProfileController(), 'index'], $request, $response); }, [\App\Web\Middleware\ActionMiddleware::class] ); } ~~~ 規則詳解: - ` /profile/{id:\d+}` 匹配的 url 規則 - `[\App\Web\Controllers\ProfileController::class, 'index']` 匹配后執行的方法,callable 類型 - `[\App\Web\Middleware\ActionMiddleware::class]` 該路由的中間件 通過 `Mix\Http\Message\ServerRequest` 獲取變量值: ~~~php $id = $request->getAttribute('id'); ~~~ 更多規則請查看: - [https://github.com/nikic/FastRoute](https://github.com/nikic/FastRoute)
                  <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>

                              哎呀哎呀视频在线观看