代码之家  ›  专栏  ›  技术社区  ›  Gaylord.P

在外部包中加载routes.yaml而不进行配置。在项目中

  •  1
  • Gaylord.P  · 技术社区  · 7 年前

    有了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;
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   i.am.michiel    7 年前

    您可以简单地将导入添加到 config/routes.yaml 文件:

    fineuploaderbundle:
        resource: "@FineUploaderBundle/Resources/config/routes.yaml"
    
    推荐文章