0

ZF2 ..を使用して多言語アプリケーションを作成していますが、モジュールに関係なく、各URLのベースを形成するパーツURLを追加する方法を決定できません。

http://localhost/en/us/application/index/index/

/[:namespace[/:controller[/:action]]]DIを使用して構成する方法を完全に理解しています

http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/

私が理解していないのは、すべてのルートのベースとなるパーツルートを構成する方法です。ZF1では、これを実現するためにルートチェーンを使用しました。

そのため、サイト全体に適用されるパートルートを構成してから/[:lang[/:locale]]、モジュールに構成する/[:namespace[/:controller[/:action]]]か、その他の必要なルートを設定する必要があります。

http://localhost/en/us/application/index/index/
http://localhost/zh/cn/application/index/index/
http://localhost/en/uk/forum/index/index/
4

1 に答える 1

2

child_routesあなたが探しているのは設定キーだと思います。ZfcUserがルーティングを構成する方法を見てください(ここ) :ベースリテラルルート(/ user)を作成し、child_routes配列を介してサブルート(/ user / loginなど)をチェーンします。

私はこのような何かがあなたのためにトリックをするだろうと思います:

'router' => array(
    'routes' => array(
        'myapp' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/[:lang[/:locale]]',
                'defaults' => array(
                    'lang'   => 'en',
                    'locale' => 'us',
                ),
            ),
            'may_terminate' => false,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    ),
                    'defaults' => array(
                        'controller' => 'index',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),
),

次に、コントローラーでこれを実行して、言語とロケールを取得できます。

$this->params()->fromRoute('lang');
$this->params()->fromRoute('locale');
于 2012-06-27T12:58:46.647 に答える