有了symfony 4,我想加载 routes.yaml 在我的自定义外部包中。我创建了扩展类 Load 但没有加载(资源: https://symfony.com/doc/current/routing/custom_route_loader.html#more-advanced-loaders )
routes.yaml
Load
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; } }
您可以简单地将导入添加到 config/routes.yaml 文件:
config/routes.yaml
fineuploaderbundle: resource: "@FineUploaderBundle/Resources/config/routes.yaml"