所以我一直在关注zend 2的骨架示例"album"。我遵循了每一步,但我无法逃脱404错误-无论何时输入,请求的URL都无法通过路由匹配http://hostname/album用于索引,或http://hostname/album/add用于添加等
很自然,我研究了module.config.php文件中的路由:
<?php
return array(
'controllers' => array(
'invokables' => array(
'Album'Controller'Album' => 'Album'Controller'AlbumController',
),
),
'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',
),
),
);
这里的一切看起来都很好,所以我查看了Module.php,其中Module.config.php从加载
<?php
namespace Album;
use Zend'ModuleManager'Feature'AutoloaderProviderInterface;
use Zend'ModuleManager'Feature'ConfigProviderInterface;
class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend'Loader'ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend'Loader'StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
再说一遍,这里一切看起来都很好。现在我想问题可能是我没有在application.config.php文件中包含Album模块(已删除注释):
<?php
return array(
'modules' => array(
'Application',
'Album',
),
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
'config_glob_paths' => array(
'config/autoload/{{,*.}global,{,*.}local}.php',
),
);
但是它也包括在内。我还有AlbumController.php和视图(.phtml)文件,它们应该在哪里。我多次仔细检查路径,但路由仍然不起作用。有什么想法吗?任何建议都将不胜感激。
PS-我使用的是Ubuntu 14.04虚拟盒子。
编辑
以下是应用程序的目录结构:(我只是列出相关的文件/文件夹,使其更可读)
- ZendSkel
- 公众
- index.php
- 配置
- application.config.php
- 模块
- 应用程序
- 相册
- Module.php
- 配置
- 模块配置.php
- src
- 相册
- 控制器
- AlbumController.php
- 型号
- 表单
- 控制器
- 相册
- 视图
- 相册
- 相册
- index.phtml
- 添加.phtml
- edit.phtml
- 删除.phtml
- 相册
- 相册
- 公众
另外,我使用的是带有apache2.2的虚拟主机。
对于仍在寻找此问题解决方案的任何人,
清除数据/缓存文件夹,允许路由按预期工作。
就像@Mayank Awasthi说的:
清除数据/缓存文件夹,允许路由作为预期。
这适用于ZendANDLaminas。
如果问题与缓存无关,请检查您的配置和路由文件!
如果你按照官方页面中的教程一步一步进行,它会显示404。确保1-停止发球,2-输入";composer development enable";。3-输入";作曲家服务";然后它就会起作用。教程确实提到了";composer development enable;但它没有按正确的顺序提及它,这就是为什么很多人一直在获得404 的原因