2
我使用ZF2骨架的應用程序。
若要在現有模塊一個新的控制器,我修改了module.config.php文件是這樣的:問題Zend框架2(ZF2)在創建新的控制器
<?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/相片 /索引)按預期方式工作。
此鏈接(http://domainname.com/dummy/zend/zf2-tutorial/public/專輯 /指數)不工作,並顯示以下錯誤:
A 404 error occurred Page not found.
The requested URL could not be matched by routing.
呃裏面,你做的路線是相同的,沒有辦法將它們分開。第二條路線可能應該是''route'=>'/ photo [/:action] [/:id]',' – Sam
這顛倒了場景。現在,第二個環節是工作,第一個是顯示錯誤:「出現了404錯誤頁面沒有找到 所請求的網址無法通過路由匹配。」 –
我使用相同的模塊(相冊)和2個控制器(AlbumController.php,PhotoController.php)。這是問題嗎? –