【问题标题】:I cant generate URL with router service when JMSI18nRoutingBundle is in use - Symfony 2.7使用 JMSI18nRoutingBundle 时,我无法使用路由器服务生成 URL - Symfony 2.7
【发布时间】:2016-06-27 12:40:23
【问题描述】:
$this->getServiceContainer()->get('router')->getGenerator()->generate('ting_user_reset_password', array(), UrlGeneratorInterface::ABSOLUTE_URL);

当我尝试使用路由名称 ting_user_reset_password 生成带有 router 服务的 URL 时,会发生异常,因为使用 JMSI18nRoutingBundle 时,路由名称不存在。

 /**
 * @Route("/reset-password", name="ting_user_reset_password")
 * @Template()
 */
public function resetPasswordAction(){

}

JMSI18nRoutingBundle 创建以下路由:

us_US_RG_ting_user_reset_password
de_DE_RG_ting_user_reset_password
es_ES_RG_ting_user_reset_password
...

如果您为此路由禁用 JMSI18nRoutingBundle,则路由器服务可以正常工作:

 /**
 * @Route("/reset-password", name="ting_user_reset_password", options={"i18n" = false})
 * @Template()
 */
public function resetPasswordAction(){

}

如何通过指定路由名称使用路由服务获取URL?

谢谢。

【问题讨论】:

    标签: symfony routing


    【解决方案1】:

    我做了很多测试,使用捆绑包“JMSI18nRoutingBundle”时生成url的正确方法如下:

    $this->getServiceContainer()->get('router')->generate('ting_user_reset_password', array(), UrlGeneratorInterface::ABSOLUTE_URL);
    

    没有getGenerator()->

    这对我来说很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      • 2021-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 1970-01-01
      相关资源
      最近更新 更多