【问题标题】:Symfony2 Routing issue with multiple bundle and configuration levelsSymfony2 具有多个捆绑和配置级别的路由问题
【发布时间】:2015-12-14 13:38:27
【问题描述】:

我有一个项目,在 Symfony2 中每个活动域安排了多个捆绑包。该项目在以下域下运行:我的本地 WAMP :Agapp.local,具有以下 app/config/routing.yml

ag_app:
    resource: "@AgAppBundle/Resources/config/routing.yml"
    prefix:   /

ag_apsa:
    resource: "@AgApsaBundle/Resources/config/routing.yml"
    prefix:   /apsa

ag_training:
    resource: "@AgTrainingBundle/Resources/config/routing.yml"
    prefix:   /training

ag_intern:
    resource: "@AgInternBundle/Resources/config/routing.yml"
    prefix:   /parents/intern

ag_parents:
    resource: "@AgParentsBundle/Resources/config/routing.yml"
    prefix:   /parents

ag_circo:
    resource: "@AgCircoBundle/Resources/config/routing.yml"
    prefix:   /circo

ag_ecole:
    resource: "@AgEcoleBundle/Resources/config/routing.yml"
    prefix:   /ecole

AgApsaBundle 有以下主路由文件:

ag_apsa_homepage:
    path:     /
    defaults: { _controller: AgrementApsaBundle:Apsa:index }

ag_apsa:
    resource: "@AgrementApsaBundle/Resources/config/routing/apsa.yml"
    prefix:   /

这里是 AgApsaBundle.yml 的内容:

apsa:
   path:     /
   defaults: { _controller: "AgrementApsaBundle:Apsa:index" }

apsa_show:
    path:    /{id}/show
    defaults: { _controller: "AgApsaBundle:Apsa:show" }

apsa_new:
    path:     /new
    defaults: { _controller: "AgApsaBundle:Apsa:new" }

apsa_create:
    path:     /create
    defaults: { _controller: "AgApsaBundle:Apsa:create" }
    requirements: { _method: post }

apsa_edit:
    path:     /{id}/edit
    defaults: { _controller: "AgApsaBundle:Apsa:edit" }

apsa_update:
    path:     /{id}/update
    defaults: { _controller: "AgApsaBundle:Apsa:update" }
    requirements: { _method: post|put }

apsa_delete:
    path:    /{id}/delete
    defaults: { _controller: "AgApsaBundle:Apsa:delete" }
    requirements: { _method: post|delete }  

AppKernel 信息:

new Ag\Metiers\Etab\EcoleBundle\AgEcoleBundle(), new Ag\Metiers\Etab\CircoBundle\AgCircoBundle(), new Ag\Metiers\Parents\ParentsBundle\AgParentsBundle(), new Ag\Metiers\Parents\InternBundle\AgInternBundle(), new Ag\Metiers\Training\TrainingBundle\AgTrainingBundle(), new Ag\Metiers\TrainingApsaBundle\AgApsaBundle(), new Ag\AppBundle\AgAppBundle(),

router:debug 命令确认所有路由都已正确注册和列出。 但是,尝试访问 AgApp.local/apsa 或与 Apsa 捆绑包相关的任何其他路由时,它会返回“未收到数据,无法加载网页,因为服务器未发送数据。”,而日志注册找到了一个 macthed 路由。相反,尝试AgApp.local/apsa/parents 将引发 404 错误。
您可能会发现日志跟踪here

我在路由配置中遗漏了什么吗?

【问题讨论】:

  • 您确定日志匹配正确的路径吗?查找 symfony 的内核信息级别以检查匹配的路由。由于您使用的是 WAMP,我可以想象您在重写时会遇到一些问题!
  • [2015-12-14 15:39:35] request.INFO: Matched route "ag_apsa_homepage" (parameters: "_controller": "Ag\Metiers\Training\ApsaBundle\Controller\ApsaController::indexAction", "_route": "ag_apsa_homepage") [] [] 是的,它们在内核中已适当定义(请参阅更新的问题)
  • 您可以尝试使用结尾的斜线访问AgApp.local/apsa/ 并告诉我您是否采取行动?
  • 它返回相同的结果,因为使用适当的操作(来自日志)找到路由但没有返回任何内容
  • 好的。正如我看到的那样,您确实遇到了配置问题,因为您的每个配置级别都有多个前缀。我建议您将特定路由移动到 app/config/routing.yml 以进行测试,然后尝试将其移动到特定于捆绑包的配置中。测试时请记住注释/删除包引用

标签: symfony routing routes


【解决方案1】:

经过更多研究,我发现路由本身不是问题的原因。而是Doctrine,您可以找到相关问题here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 2018-11-05
    • 2013-04-23
    相关资源
    最近更新 更多