我正在使用 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.