在Symfony2中使用语言环境前缀路由

时间:2012-01-20 22:03:47

标签: internationalization routing routes symfony locale

这是我的设置,标准版有点改变。

# app/config/routing.yml
_internal:
    resource: "@AcmeDemoBundle/Controller/"
    prefix: /{_locale}
    requirements:
        _locale: en|sr

并在security.yml中添加了/ {_ locale}。

之前的路线:

Name                      Method Pattern
_welcome                  ANY    /
_demo_login               ANY    /demo/secured/login
_security_check           ANY    /demo/secured/login_check
_demo_logout              ANY    /demo/secured/logout
acme_demo_secured_hello   ANY    /demo/secured/hello
_demo_secured_hello       ANY    /demo/secured/hello/{name}
_demo_secured_hello_admin ANY    /demo/secured/hello/admin/{name}
_demo                     ANY    /demo/
_demo_hello               ANY    /demo/hello/{name}
_demo_contact             ANY    /demo/contact
_wdt                      ANY    /_wdt/{token}
_profiler_search          ANY    /_profiler/search
_profiler_purge           ANY    /_profiler/purge
_profiler_import          ANY    /_profiler/import
_profiler_export          ANY    /_profiler/export/{token}.txt
_profiler_search_results  ANY    /_profiler/{token}/search/results
_profiler                 ANY    /_profiler/{token}
_configurator_home        ANY    /_configurator/
_configurator_step        ANY    /_configurator/step/{index}
_configurator_final       ANY    /_configurator/final

之后的路线:

Name                      Method Pattern
_welcome                  ANY    /
_wdt                      ANY    /_wdt/{token}
_profiler_search          ANY    /_profiler/search
_profiler_purge           ANY    /_profiler/purge
_profiler_import          ANY    /_profiler/import
_profiler_export          ANY    /_profiler/export/{token}.txt
_profiler_search_results  ANY    /_profiler/{token}/search/results
_profiler                 ANY    /_profiler/{token}
_configurator_home        ANY    /_configurator/
_configurator_step        ANY    /_configurator/step/{index}
_configurator_final       ANY    /_configurator/final
_demo_login               ANY    /{_locale}/demo/secured/login
_security_check           ANY    /{_locale}/demo/secured/login_check
_demo_logout              ANY    /{_locale}/demo/secured/logout
acme_demo_secured_hello   ANY    /{_locale}/demo/secured/hello
_demo_secured_hello       ANY    /{_locale}/demo/secured/hello/{name}
_demo_secured_hello_admin ANY    /{_locale}/demo/secured/hello/admin/{name}
_demo                     ANY    /{_locale}/
_demo_hello               ANY    /{_locale}/hello/{name}
_demo_contact             ANY    /{_locale}/contact

对于No route found for "GET /en/demo/hello/World"网址,哪一个导致/en/demo/hello/World

知道如何解决这个问题吗?

此外,我想实现每个域语言环境。我正在尝试https://github.com/schmittjoh/JMSI18nRoutingBundle,但由于某种原因,它不适用于最新的Symfony 2.0.9,至少对我而言。我正在关注doc,但在尝试使用前缀网址时遇到类似的404错误。

1 个答案:

答案 0 :(得分:0)

在Symfony版本2.0.9中,无法在前缀中定义占位符的默认值和要求。你必须升级到2.1,目前正在积极开发中。

相关问题