如何将yaml路由注册为PHP?

如何将yaml路由注册为PHP?,php,symfony,Php,Symfony,首先,我添加了一个新的路由_dev文件作为php framework: router: # resource: "%kernel.root_dir%/config/routing_dev.yml" resource: "%kernel.root_dir%/config/routing_dev.php" strict_requirements: true profiler: { only_exceptions: false } 现在我

首先,我添加了一个新的路由_dev文件作为php

framework:
    router:
#        resource: "%kernel.root_dir%/config/routing_dev.yml"
        resource: "%kernel.root_dir%/config/routing_dev.php"
        strict_requirements: true
    profiler: { only_exceptions: false }
现在我正在根据

但是,当我注册yaml路线示例时,我遇到了一个问题:

gabriel_auth:
    resource: "@GabrielAuthBundle/Controller/"
    type:     annotation
    prefix:   /

gabriel_messaging:
    resource: "@GabrielMessagingBundle/Controller/"
    type:     annotation
    prefix:   /
像档案上的这个

$collection->addCollection(
    $loader->import("@GabrielAuthBundle/Controller/", "annotation")
);

$collection->addCollection(
    $loader->import("@GabrielMessagingBundle/Controller/", "annotation")
);
然而,它确实起作用了 我找不到将这些类型的资源添加到集合的方法:

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler
这是我最好的尝试

$collection->addCollection(
    $loader->import(
        '@WebProfilerBundle/Resources/config/routing/profiler.xml')->addPrefix('/_profiler')
);

$collection->addCollection(
    $loader->import(
   '@WebProfilerBundle/Resources/config/routing/wdt.xml')->addPrefix('/_wdt')
);
它抛出了这个错误

FileLoaderLoadException:可捕获致命错误:参数1传递给 Symfony\Component\Routing\RouteCollection::addCollection()必须是 Symfony\Component\Routing\RouteCollection的实例,给定空值

根据文件

此函数没有返回

这就是为什么会出现
null

尝试:

根据文件

此函数没有返回

这就是为什么会出现
null

尝试:

根据文件

此函数没有返回

这就是为什么会出现
null

尝试:

根据文件

此函数没有返回

这就是为什么会出现
null

尝试:

public addPrefix(string $prefix, array $defaults = array(), array    $requirements = array())

 Adds a prefix to the path of all child routes.

Parameters
string  $prefix     An optional prefix to add before each pattern of the route collection
array   $defaults   An array of default values
array   $requirements   An array of requirements
$profilerCollection = $loader->import(  '@WebProfilerBundle/Resources/config/routing/profiler.xml');
$profilerCollection->addPrefix('/_profiler');
$collection->addCollection( $profilerCollection);