Проблема в создании нового контроллера в Zend Framework 2 (ZF2)

Я использую приложение ZF2 Skeleton.
Чтобы создать новый контроллер в существующем модуле, я изменил файл module.config.php следующим образом:

<?php return array( 'controllers' => array( 'invokables' => array( 'Album\Controller\Album' => 'Album\Controller\AlbumController', // WORKING FINE 'Album\Controller\Photo' => 'Album\Controller\PhotoController', // I ADDED THIS ), ), // The following section Was PREVIOUSLY THERE 'router' => array( 'routes' => array( 'album' => array( 'type' => 'segment', 'options' => array( 'route' => '/album[/:action][/:id]', 'constraints' => array( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]+', ), 'defaults' => array( 'controller' => 'Album\Controller\Album', 'action' => 'index', ), ), ), ), ), // ADDED THIS FOR NEW CONTROLLER 'PhotoController.php' in same Namespace 'Album' 'router' => array( 'routes' => array( 'photo' => array( 'type' => 'segment', 'options' => array( 'route' => '/photo[/:action][/:id]', 'constraints' => array( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]+', ), 'defaults' => array( 'controller' => 'Album\Controller\Photo', 'action' => 'index', ), ), ), ), ), 'view_manager' => array( 'template_path_stack' => array( 'album' => __DIR__ . '/../view', ), ), );` 

Эта ссылка ( http://domainname.com/dummy/zend/zf2-tutorial/public/ photo / index) работает так, как ожидалось.

Эта ссылка ( http://domainname.com/dummy/zend/zf2-tutorial/public/ album / index) не работает и показывает следующие ошибки:

 A 404 error occurred Page not found. The requested URL could not be matched by routing. 

Проблема в том, что вы дважды объявляете router в своем конфиге, второй перезаписываете первый, поэтому используется только второй маршрут.

Ваш файл конфигурации должен выглядеть примерно так: оба маршрута внутри одной и той же декларации router

 <?php return array( 'controllers' => array( 'invokables' => array( 'Album\Controller\Album' => 'Album\Controller\AlbumController', // WORKING FINE 'Album\Controller\Photo' => 'Album\Controller\PhotoController', // I ADDED THIS ), ), // The following section Was PREVIOUSLY THERE 'router' => array( 'routes' => array( 'album' => array( 'type' => 'segment', 'options' => array( 'route' => '/album[/:action][/:id]', 'constraints' => array( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]+', ), 'defaults' => array( 'controller' => 'Album\Controller\Album', 'action' => 'index', ), ), ), // This is where your new route goes 'photo' => array( 'type' => 'segment', 'options' => array( 'route' => '/photo[/:action][/:id]', 'constraints' => array( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]+', ), 'defaults' => array( 'controller' => 'Album\Controller\Photo', 'action' => 'index', ), ), ), ), ), 'view_manager' => array( 'template_path_stack' => array( 'album' => __DIR__ . '/../view', ), ), );