Zend Framework 2には、モジュールへのルーティングという概念はありません。すべてのルーティングマッピングは、URIパターン(HTTPルートの場合)と特定のコントローラクラスの間にあります。つまり、Zend\Mvc
はイベントリスナー(Zend\Mvc\ModuleRouteListener
)を提供しています。これにより、与えられたパターンに基づいて複数のコントローラにマップするURIパターンを定義し、「モジュールルーティング」をエミュレートできます。このような経路を定義するには、あなたのルーティング設定としてこれを置きます:
'router' => array(
'routes' => array(
// This defines the hostname route which forms the base
// of each "child" route
'home' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'site.com',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This Segment route captures the requested controller
// and action from the URI and, through ModuleRouteListener,
// selects the correct controller class to use
'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',
),
),
),
),
),
),
),
(Click here to see an example of this @ ZendSkeletonApplication)
をこれは、しかし、方程式の半分だけです。特定の命名形式を使用して、モジュール内のすべてのコントローラクラスも登録する必要があります。これは、同じ構成ファイルを介して行われます:
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController'
),
),
配列のキーがModuleRouteListenerは、右のコントローラを見つけるために使用する別名であり、それは次の形式にする必要があります
<Namespace>\<Controller>\<Action>
値この配列キーに割り当てられるのは、コントローラクラスの完全修飾名です。
(Click here to see an example of this @ ZendSkeletonApplication)
注:ZendSkeletonApplicationを使用していない、またはそれがデフォルトアプリケーション・モジュールの取り外しを行った場合は、あなたがあなた自身のモジュールの1つにModuleRouteListenerを登録する必要があります。 Click here to see an example of how ZendSkeletonApplication registers this listener
明確で正確な説明をいただきありがとうございます。私はあなたの解決策を取った。私はこれでずっと苦労しました。 – Sapher
それは素晴らしかった、ありがとう。 – cr125rider
私はmamp proを使用し、仮想ホスト名にサブドメインを作成します。したがって、reseller.myhost.com/testを使用した後はokeyですが、reseller.myhostと書いてください。私のモジュールのindexactionではないインデックスに行く –