请注意“发生404错误”无法通过路由“在ZF2中”匹配请求的URL。
给我带来麻烦的部分是这样的:
'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(
'__NAMESPACE__' => 'Album\Controller',
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
你的路线是对的! (默认情况下不需要NameSpace)
// The following section is new and should be added to your file
'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',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
你必须在application.config.php中添加你的模块(你说你已经完成了它。)
// This should be an array of module namespaces used in the application.
'modules' => array(
'Application',
'Album'
),
1)在类型中使用“段”而不是“段”。 2)在路线上 使用route'=>'/ album [/] [:action] [/:id]',
而不是'route'=>'/ album [/:action] [/:id]',
3)
加
// getAutoloaderConfig() and getConfig() methods here
public function getAutoloaderConfig() {
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig() {
return include __DIR__ . '/config/module.config.php';
}
Module.php