我已經從ZF2 Skeleton Application開始。我有一個叫Application
的模塊。在該模塊內部,我添加了我自己的ShopController
。它在module.config.php
中註冊,看起來像這樣。Zend Framework 2(ZF2)404調用動作時未發現頁面錯誤
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'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__' => 'Application\Controller',
'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(
'Application\Controller\Index' => 'Application\Controller\IndexController',
'Application\Controller\Shop' => 'Application\Controller\ShopController',
),
),
[... service_manager,translator,view_manager as in skeleton app ...]
);
我能達到通過瀏覽店鋪控制器的index動作my.example.com/shop/但是當我試圖達成一個不同的動作,例如my.example.com/shop/add不起作用。我得到了404.
我錯過了什麼?
我是新手,以及在Zend的,但在你的ShopController類你有它返回一個視圖或一個空數組() – vdua 2013-03-26 10:21:01
感謝指點出來,是的,它的存在方式的addAction。 :) – twigmac 2013-03-26 10:26:46
和add.phtml在視圖目錄中? – vdua 2013-03-26 10:41:03