我已经从ZF2骨架应用程序开始。我有一个模块叫Application
。在这个模块中,我添加了我自己的ShopController
。它在module.config.php
中注册,看起来像这样。
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'ZendMvcRouterHttpLiteral',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'ApplicationControllerIndex',
'action' => 'index',
),
),
),
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'ApplicationController',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'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(
),
),
),
),
),
'shop' => array(
'type' => 'segment',
'options' => array(
'route' => '/shop[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'ApplicationController',
'controller' => 'Shop',
'action' => 'index',
),
'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(
),
),
),
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'ApplicationControllerIndex' => 'ApplicationControllerIndexController',
'ApplicationControllerShop' => 'ApplicationControllerShopController',
),
),
[... service_manager,translator,view_manager as in skeleton app ...]
);
我可以通过浏览到my.example.com/shop/到达商店控制器的索引动作,但当我试图达到不同的动作,例如my.example.com/shop/add它不工作。我得到一个404。
我错过了什么?
我尝试添加may_terminate = true,它正在工作,还删除了child_routes做工作。
'shop' => array(
'type' => 'segment',
'options' => array(
'route' => '/shop[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'ApplicationController',
'controller' => 'Shop',
'action' => 'index',
),
),
'may_terminate' => true, // I added this
'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(
),
),
),
),
),