答案 0 :(得分:1)
我找到了一个非常好的解决方案,虽然它并不完美:
基本上我使用'routing.loader'服务加载特定包的路由集合。然后我创建自己的UrlMatcher来匹配这些路线。
// Get the route collection for the app's bundle
$kernel = $this->container->get('kernel');
$routingFilesLocation = $kernel->locateResource( '@'. $app->getBundle() . '/Controller/' );
$routeLoader = $this->container->get('routing.loader');
$collection = $routeLoader->load( $routingFilesLocation );
// Ensure that we don't get in a redirect loop when
// loading the dashboard of core
$collection->remove( '_core_redirect_home' );
// Try to match the rest of the url to one of the routes
$router = $this->container->get('router');
$routeString = $routingFilesLocation . "<br/>";
$url = "/" . $garbage;
$matcher = new UrlMatcher( $collection, $router->getContext() );
try
{
$routes = $matcher->match( $url );
}
catch( ResourceNotFoundException $e )
{
throw $this->createNotFoundException( 'Could not find "' . $url . '" route within ' . $app_name );
}
$response = $this->forward( $routes['_controller'] );
这里的问题是我硬编码只在包中的“Controller”文件夹中查找控制器。