在没有配置的情况下在外部包中加载 routes.yaml。在项目中

Load routes.yaml in external bundle without config. in project

使用 Symfony 4,我想在我的自定义外部包中加载 routes.yaml。我创建了 class extended 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;
    }
}

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

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

https://symfony.com/doc/current/bundles/override.html#routing

Routing is never automatically imported in Symfony. If you want to include the routes from any bundle, then they must be manually imported from somewhere in your application (e.g. config/routes.yaml).