2013-04-27 122 views
1

我试图前缀单个控制器内的所有路由与_locale,但到目前为止,我还没有成功:语言环境中路由前缀

/** 
* @Route("/{_locale}/events", requirements={"_locale": "en"}) 
* @Route("/{_locale}/evenements", requirements={"_locale": "fr"}) 
*/ 
class SomeController extends Controller{ 

    /** 
    * @Route("/", name="events") 
    */ 
    public function indexAction(){ 
     ... 
    } 

    ... 
} 

route:debug甚至没有列出了第二@Route前缀的网址。我尝试删除_locale slu al,但仍然无法找到路线。

我在这里错过了什么吗?甚至有可能有多个前缀?

任何帮助将不胜感激......

+1

你为什么不使用[JMSI18nRoutingBundle(https://github.com/schmittjoh/JMSI18nRoutingBundle)? – Crozin 2013-04-27 16:03:02

+0

是的,我当时(目前是禁用的),但后来我意识到它不支持slu translation翻译 - 不是这种特殊情况。也许问得太多了? :)我需要的路线翻译的要求'... – 2013-04-27 16:10:29

+0

@jperovic最近发布了一个[类似问题](https://github.com/symfony/symfony/issues/7724)。您可以尝试将Symfony降级到2.1。或者,您可以尝试在单独的配置文件中定义多个路由 - 值得一试。 – gilden 2013-04-28 00:00:55

回答

0

首先,你已经在你的文件Ressources /配置/ routing.yml中,您使用注解此控制器界定?

#file Ressources/config/routing.yml 
blog: 
    resource: "@YourBundle/Controller" 
    type:  annotation 

你也可以定义你的路由为:

/** 
* @Route("/en/events", defaults={"_locale": "en"}) 
* @Route("/fr/evenements", defaults={"_locale": "fr"}) 
*/ 
+0

我在一个使用这个“手动”解决方案的项目上,在尝试了JMSI18nRoutingBundle之后,是的,这个捆绑包是我推荐的一个很好且简单的解决方案。 – Alcalyn 2014-03-17 14:19:29