路由
路由已经作为中间件实现。我们仍然使用 FastRoute 作为默认的路由器,但它与之没有紧密耦合。
如果你想要使用另一个路由库,你可以通过创建自己的路由接口实现来实现。DispatcherInterface、RouteCollectorInterface、RouteParserInterface 和 RouteResolverInterface 在 Slim 的组件和路由库之间创建了一个桥梁。
如果你正在使用 determineRouteBeforeAppMiddleware,你需要在调用 run() 之前在应用程序中添加 Middleware\RoutingMiddleware 中间件,以保持以前的行为。
使用方法
<?php
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
// 添加路由中间件
$app->addRoutingMiddleware();
// ...
$app->run();