在没有配置的外部包中加载 routes.yaml.在项目中 [英] Load routes.yaml in external bundle without config. in project

查看:17
本文介绍了在没有配置的外部包中加载 routes.yaml.在项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Symfony 4,我想在我的自定义外部包中加载 routes.yaml.我创建了类扩展 Load 但它没有加载(资源:https://symfony.com/doc/current/routing/custom_route_loader.html#more-advanced-loaders )

With Symfony 4, I want to load routes.yaml in my custom external Bundle. I created class extended Load but it's not loaded ( Resource : 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;
    }
}

推荐答案

您可以简单地在现有的主要 config/routes.yaml 文件中添加导入:

You could simply add the import in the main existing config/routes.yaml file :

fineuploaderbundle:
    resource: "@FineUploaderBundle/Resources/config/routes.yaml"

这篇关于在没有配置的外部包中加载 routes.yaml.在项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆