Symfony2的束继承父失去路线捆绑 [英] Symfony2 bundle inheritance losing parent bundles routes

查看:134
本文介绍了Symfony2的束继承父失去路线捆绑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在指示这里创建一个简单的束继承,撞上了问题的路线。我使用的注解路由。当我App​​Kernel.php登记我的孩子我的包都其父包路由丢失。

I am trying to create a simple bundle inheritance as instructed in here and ran into a problem with routes. I'm using annotations for routing. When I register my child bundle in AppKernel.php all my parent bundles routes are lost.

有关我从文档Symfony2的理解应该是所有文件,包括路线,首先从孩子包,然后从父包。既然没有发生,唯一的孩子捆绑控制器似乎被加载。

For what I understand from the documentation Symfony2 should look all files, including routes, first from the child bundle and then from the parent bundle. Now that is not happening, only child bundles controllers seems to be loaded.

在我的孩子捆绑我已经实现的getParent功能的指示捆绑文件,并在我的routing.yml我有:

In my child bundles Bundle file I have implemented getParent function as instructed, and in my routing.yml I have:

ParentBundle:
resource: "@Parent/Controller/"
type:     annotation
prefix:   /admin/

这继承之前的罚款。

which worked fine before the inheritance.

我已经测试,该系统工作正常,如果在sepa​​retely包括所有的routing.yml文件的控制器,但似乎非常繁琐的方式,使继承,因为我只是想重写父束(不是所有控制器的几个部分工作)。

I have tested that the system works fine if in include all controller files separetely in routing.yml but that seems very cumbersome way to make the inheritance to work as I only want to override few parts of the parent bundle ( not all controllers ).

探查器显示我的两个包作为活跃。

Profiler is showing both of my bundles as active.

推荐答案

我找到了这个问题的解决方案。今天,我也试图与覆盖路由注解配置的父包还发现,如果anotation路由进口整捆(@ SomeBundle /控制器)母公司路线被忽略了。

I found the right solution for this issue. Today I was also trying to override a parent bundle configured with annotations routing and also found that parent routes were ignored if the anotation routing imported the whole bundle ("@SomeBundle/Controller").

一点点调试我发现,对此的解释是,如果你使用@作为preFIX的控制器,这将传递给内核解析器将只返回子资源,如果父资源已经经过覆盖。因此,解决办法是提供包的完整路径,考虑到内核将尝试将资源从匹配的应用程序/资源的,所以你必须添加一个相对目录(../../ )的实际路径前:

After a little debugging I found that the explanation for this is that if you use "@" as prefix for the controller this will pass to the kernel resolver which will return ONLY the child resource if the parent resource has been overridden. So the solution is to provide the full path of the bundle, considering that the kernel will try to match the resource from app/Resources so you will have to add a relative directory (../../) before the actual path:

# app/config/routing.yml:
some_parent:
    resource: "../../src/Application/ParentBundle/Controller"
    type: annotation

# ChildBundle implements getParent() method to inherit from ParentBundle
some_child:
    resource: "@ChildBundle/Controller"
    type: annotation

这将如预期:所有父路径将被导入,并通过在孩子捆绑指定的所有航线覆盖

This will work as expected: all parent routes will be imported and will be overridden by all routes specified in the child bundle.

这篇关于Symfony2的束继承父失去路线捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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