Zend Framework 2 - Zend \ MVC \ Router \ HTTP \ Part - モジュール構成
-
12-12-2019 - |
質問
ZF2を使用して多言語アプリケーションを作成しています..モジュールに関係なく各URLのベースを形成する部品のURLを追加する方法を決定できません。
http://localhost/en/us/application/index/index/
.
DI を使用して/[:namespace[/:controller[/:action]]]
を構成する方法を完全に理解しています
http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/
.
私が理解していないのは、経路の基準となる部分ルートを設定する方法です。ルートチェーンを使用しました。
だから私はサイト全体を適用した/[:lang[/:locale]]
の part ルートを設定する必要があります。
.http://localhost/en/us/application/index/index/
http://localhost/zh/cn/application/index/index/
http://localhost/en/uk/forum/index/index/
解決
あなたが探しているものは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',
),
),
),
),
),
),
.
それからあなたのコントローラー内でLangとLocaleを取得するためにこれを行うことができます:
$this->params()->fromRoute('lang');
$this->params()->fromRoute('locale');
. 所属していません StackOverflow