繁体   English   中英

Zend Expressive中的FastRoute组

[英]FastRoute Groups in Zend Expressive

我想在Expressive中使用FastRoute的路由组。 像样品:

$router = $app->getContainer()->get(FastRoute\RouteCollector::class);

$router->get('/', App\Action\HomePageAction::class);

$router->addGroup('/pages', function (FastRoute\RouteCollector $router) {
    $router->get('', App\Action\PagesIndexAction::class);
    $router->get('/add', App\Action\PagesAddAction::class);
    $router->get('/edit/{id}', App\Action\PageEditActionFactory::class);
    $router->post('/edit/{id}', App\Action\PageEditActionFactory::class);
    $router->get('/another/{section}[/{subsection}]', PagesAnotherActionFactory::class);  
});

我在docs中创建了工厂( https://docs.zendframework.com/zend-expressive/features/router/fast-route/#advanced-configuration )并在router.global.php注册它们:

// ...
'factories' => [
    FastRoute\RouteCollector::class => App\Container\FastRouteCollectorFactory::class,
    FastRoute\DispatcherFactory::class => App\Container\FastRouteDispatcherFactory::class,
    Zend\Expressive\Router\RouterInterface::class => App\Container\RouterFactory::class,
],
// ...

现在我无法弄清楚在哪里编写配置以及如何激活它。 可以在config/router.php文件中完成吗? 请帮帮我。

只要文件与配置的其余部分合并,您就可以将它们放在config.router.php中。

'dependencies' => [
    //..
    'invokables' => [
        /* ... */
        // Comment out or remove the following line:
        // Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\FastRouteRouter::class,
        /* ... */
    ],
    'factories' => [
        /* ... */
        // Add this line; the specified factory now creates the router instance:
        FastRoute\RouteCollector::class => App\Container\FastRouteCollectorFactory::class,
        FastRoute\DispatcherFactory::class => App\Container\FastRouteDispatcherFactory::class,
        // Zend\Expressive\Router\RouterInterface::class => Zend\Expressive\Router\FastRouteRouterFactory::class, // replaced by following line
        Zend\Expressive\Router\RouterInterface::class => App\Container\RouterFactory::class,
        /* ... */
    ],
],

请注意dependencies项键,并且您自己的RouterFactory替换了FastRouteRouterFactory因为它共享相同的配置键。

这不受支持 ,我不确定这是否可以在FastRoute中实现。

你可以检查线程“ Zend router - child routes

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM