路由已實作為中介軟體。我們仍將 FastRoute 作為預設路由器使用,但兩者並未緊密結合。如果你想實作其他路由函式庫,你可以建立自己的路由介面實作。 DispatcherInterface
、RouteCollectorInterface
、RouteParserInterface
和 RouteResolverInterface
可在 Slim 的元件和路由函式庫之間建立一座橋樑。如果你使用 determineRouteBeforeAppMiddleware
,你需要為你的應用程式在呼叫 run()
之前新增 Middleware\RoutingMiddleware
中介軟體才能維持之前的行為。
<?php
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
// Add Routing Middleware
$app->addRoutingMiddleware();
// ...
$app->run();