2017-05-21 7 views
3

ExpressRouteのルートグループをExpressiveで使用します。 サンプルのように: 私は(https://docs.zendframework.com/zend-expressive/features/router/fast-route/#advanced-configuration)ドキュメントに書かれた工場を作成しZendの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); 
}); 

そして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で実行できますか? 助けてください。

答えて

1

ファイルは残りの設定とマージされる限り、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キーと、それはあなた自身のRouterFactoryFastRouteRouterFactoryを置き換えます。