1

Symfony2 ルーティングのロケールとサブドメイン パターンのいくつかの側面で誤解しているようです。

なぜこれが機能しないのですか?

routing_de:
    host: "dev.de.example.com" 
    resource: "@AcmeDemoBundle/Resources/config/routing_de.yml"
    prefix: /


routing_en:
    host: "dev.en.example.com" 
    resource: "@AcmeDemoBundle/Resources/config/routing_en.yml"
    prefix: /

さらに、サブドメインに基づいてロケールを設定したいと考えています。このようにデフォルトのロケールを設定すると思います:

routing_de:
    host: "dev.{_locale}.example.com" 
    resource: "@AcmeDemoBundle/Resources/config/routing_{_locale}.yml"
    requirements:
         _locale: de|en
    prefix: /

ここで説明したサブドメイン リスナーを使用しても(そして Symfony2.2 に合わせて調整しても)、Controller に _locale しか設定できません。どういうわけか、Twig はコントローラーとは異なるロケールを取得します

<a href="{{ path('register', {'_locale': app.request.attributes.get('_locale')}) }} ">Register</a> 

en を返しますが、

$this->getRequest()->getLocale();

サブドメインリスナーに設定されているデフォルトのロケールを返します。

EDIT 2013/04/02 私はこのソリューションを再実装しようとしました ( http://www.ricardclau.com/2011/09/littleweb-a-small-project-in-symfony2-chapter-1-translations/ )そしてそれを調整しましたサブドメインですが、これも機能しないようです。

4

0 に答える 0