2013-03-26 39 views
0

我已經從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.

我錯過了什麼?

+0

我是新手,以及在Zend的,但在你的ShopController類你有它返回一個視圖或一個空數組() – vdua 2013-03-26 10:21:01

+0

感謝指點出來,是的,它的存在方式的addAction。 :) – twigmac 2013-03-26 10:26:46

+0

和add.phtml在視圖目錄中? – vdua 2013-03-26 10:41:03

回答

1

我試圖添加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__' => 'Application\Controller', 
        '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(
         ), 
        ), 
       ), 
      ), 
     ), 
+0

謝謝!我似乎已經在錯誤的地方定義了孩子的路線。 – twigmac 2013-03-26 11:03:33