我有一个问题,从捆绑自动路由。文件夹中有routing.yml文件: Bundle\UsersBundle\Resources\config。我正在加载路线,就像他们在Symfony食谱(loader.html)中说的那样。对于一个包,这一切都很好,但是当我将另一个包添加到AppKernel时,它不会加载新的路由。看起来每个包都需要主routing.yml中的单独条目(这正是我不想要的)。每个RoutesLoader服务都设置了正确的标记,容器正在正确地加载该服务。
routing.yml: (此配置工作,但它需要来自另一个包的RouteLoader必须返回另一个类型-- "bundle_routes_2“--当它返回"bundle_routes”路由时没有加载)
bundles_routes:
resource: .
type: bundle_routes
bundles_routes_2:
resource: .
type: bundle_routes_2更具体地说--例如,我有3个包-- UsersBundle、PermissionsBundle和GroupsBundle。每个包在其资源folder(bundle_folder/Resources/config/routing.yml).中都有路由每个包都有RoutesLoader类,如下所示:
<?php
namespace Acme\UsersBundle\Routing;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\RouteCollection;
class UsersRoutesLoader extends Loader
{
public function load($resource, $type = null)
{
$collection = new RouteCollection();
$resource = "@AcmeUsersBundle/Resources/config/routing.yml";
$type = "yaml";
$importedRoutes = $this->import($resource, $type);
$collection->addCollection($importedRoutes);
return $collection;
}
public function supports($resource, $type = null)
{
return $type === "bundle_routes";
}
}主路由文件看起来如下:
acme_bundles_routes:
resource: .
type: bundle_routes但它只适用于一个包裹。我必须将routing.yml更改为:
acme_bundles_routes:
resource: .
type: bundle_routes
acme_bundles_routes_2:
resource: .
type: bundle_routes_2
acme_bundles_routes_3:
resource: .
type: bundle_routes_3每个RoutesLoader都必须返回相应的类型。
发布于 2014-08-03 15:46:31
为什么你需要一个自定义加载程序?
请参阅http://symfony.com/doc/current/book/routing.html#routing-include-external-resources
您的父routing.yml应该包含:
AcmeBundle:
resource: "@AcmeBundle/Resources/config/routing.yml"由于您希望拥有各种路由文件,因此您可以拥有(在routing.yml中):
admin_routes:
resource: "@AcmeBundle/Resource/config/routes/admin.yml"
user_routes:
resource: "@AcmeBundle/Resource/config/routes/user.yml"以此类推。在这些包yml文件中,您将包含您的路径定义。
https://stackoverflow.com/questions/25106057
复制相似问题