首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能从Bundles自动路由

不能从Bundles自动路由
EN

Stack Overflow用户
提问于 2014-08-03 15:13:50
回答 1查看 563关注 0票数 0

我有一个问题,从捆绑自动路由。文件夹中有routing.yml文件: Bundle\UsersBundle\Resources\config。我正在加载路线,就像他们在Symfony食谱(loader.html)中说的那样。对于一个包,这一切都很好,但是当我将另一个包添加到AppKernel时,它不会加载新的路由。看起来每个包都需要主routing.yml中的单独条目(这正是我不想要的)。每个RoutesLoader服务都设置了正确的标记,容器正在正确地加载该服务。

routing.yml: (此配置工作,但它需要来自另一个包的RouteLoader必须返回另一个类型-- "bundle_routes_2“--当它返回"bundle_routes”路由时没有加载)

代码语言:javascript
复制
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类,如下所示:

代码语言:javascript
复制
<?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";
    }
}

主路由文件看起来如下:

代码语言:javascript
复制
acme_bundles_routes:
    resource: .
    type: bundle_routes

但它只适用于一个包裹。我必须将routing.yml更改为:

代码语言:javascript
复制
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都必须返回相应的类型。

EN

回答 1

Stack Overflow用户

发布于 2014-08-03 15:46:31

为什么你需要一个自定义加载程序?

请参阅http://symfony.com/doc/current/book/routing.html#routing-include-external-resources

您的父routing.yml应该包含:

代码语言:javascript
复制
AcmeBundle:
    resource: "@AcmeBundle/Resources/config/routing.yml"

由于您希望拥有各种路由文件,因此您可以拥有(在routing.yml中):

代码语言:javascript
复制
admin_routes:
    resource: "@AcmeBundle/Resource/config/routes/admin.yml"
user_routes:
    resource: "@AcmeBundle/Resource/config/routes/user.yml"

以此类推。在这些包yml文件中,您将包含您的路径定义。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25106057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档