ZF2ルーターの構成に関するヘルプを探しています。
開発コンテキストで単一のモジュールに複数のコントローラーを追加したいのですが、最終的には特定のルートを指定する方法を理解する必要があります。
これを行うために、私は現在、MVCクイックスタートドキュメントで指定されている汎用module.configを使用しようとしています。ただし、これはZF2のドキュメントが示唆するようには機能しないようです。
http://framework.zend.com/manual/2.0/en/modules/zend.mvc.quick-start.html
ドキュメントノート:
「ZendSkeletonApplicationには、このアクションに到達する可能性が高い「デフォルトルート」が付属しています。このルートでは、基本的に「/ {module} / {controller} / {action}」が必要です。これにより、次のように指定できます:「/ zend-user / hello / world」。明示的なルートを作成することをお勧めします。ここでは、主に説明のためにルートを作成します。」
ただし、コントローラーは/ landlord、/ landlord / home / indexをレンダリングしますが、/ landlord / sandbox/indexはレンダリングしません。ホームとサンドボックスはコントローラーです。Sandboxは、命名規則「SandboxController」に沿って命名されています。私の考えでは、おそらくドキュメントのコードのchild_routesセクションには、私が見逃したある種の変更が必要です。
サンドボックスインスタンスでは、404エラーページでこのエラーが発生します。
Landlord \ Controller \ Sandbox(無効なコントローラークラスまたはエイリアスに解決:Landlord \ Controller \ Sandbox)
'Landlord \ Controller \ Sandbox' =>'Landlord \ Controller \ SandboxController'を呼び出し可能オブジェクトに追加しようとしましたが、エラーが発生します。
私のコントローラーは以下のとおりです。
return array(
'controllers' => array(
'invokables' => array(
'Landlord\Controller\Home' => 'Landlord\Controller\HomeController',
),
),
'router' => array(
'routes' => array(
'landlord' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/landlord',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'Landlord\Controller',
'controller' => 'home',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default when developing a module;
// as you solidify the routes for your module, however,
// you may want to remove it and replace it with more
// specific routes.
'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(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'landlord' => __DIR__ . '/../view',
),
),
);
URLを直接構成する簡単な方法がある場合は、これも役立ちます。または、これも非常に優れたチュートリアルであるとよいでしょう。