[英]Split route configuration in zend-expressive
I'm using zend-expressive (3) to build my REST APIs. 我正在使用zend-expressive(3)构建我的REST API。 The file config/routes.php contains my routes, eg
config / routes.php文件包含我的路线,例如
return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
$app->get('/', Start\HomePageHandler::class, 'home');
$app->get('/api/ping', Start\PingHandler::class, 'api.ping');
};
Every new module adds a lot of new routes. 每个新模块都会增加很多新路线。 This gets confusing.
这变得令人困惑。 Is there a way to split the route configuration into multiple files?
有没有办法将路由配置分成多个文件?
There are 2 ways to add routes. 有两种添加路线的方法。 The first one is by how you do it, injecting the routes.
第一个是通过如何做,注入路线。 You can use a custom delegator factories to split up routes into modules.
您可以使用自定义委托工厂将路由拆分为模块。
The second is by configuration . 第二个是通过配置 。 You could created a bunch of files in a
config/routes/
dir and autoload those. 您可以在
config/routes/
目录中创建一堆文件并自动加载。 However if you prefer the routes within your modules, I suggest to stick with the first method. 但是,如果您更喜欢模块中的路由,我建议坚持使用第一种方法。
Just be aware that using both methods at the same time might cause unwanted side effects so you should choose 1 method. 请注意,同时使用这两种方法可能会导致不良的副作用,因此您应该选择一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.