对于Symfony 4,我想在自定义的外部捆绑包中加载routes.yaml
。我创建了扩展类Load
,但未加载(资源:https://symfony.com/doc/current/routing/custom_route_loader.html#more-advanced-loaders)
namespace GaylordP\FineUploaderBundle\Routing;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\RouteCollection;
class AdvancedLoader extends Loader
{
public function load($resource, $type = null): RouteCollection
{
$routes = new RouteCollection();
$importedRoutes = $this->import(
'@FineUploaderBundle/Resources/config/routes.yaml',
'yaml'
);
$routes->addCollection($importedRoutes);
dump($routes); // not executed
exit; // not executer
return $routes;
}
public function supports($resource, $type = null): bool
{
return 'advanced_extra' === $type;
}
}
答案 0 :(得分:1)
您只需将导入添加到现有的主要config/routes.yaml
文件中:
fineuploaderbundle:
resource: "@FineUploaderBundle/Resources/config/routes.yaml"
答案 1 :(得分:0)
https://symfony.com/doc/current/bundles/override.html#routing
路由绝不会自动导入到Symfony中。如果你想 包括来自任何束的路线,那么它们必须是手动的 从应用程序中的某处导入(例如config / routes.yaml)。