使用骨架模块开始一个新项目,我遇到了一些问题。我确定这是我的基本配置错误,但我无法弄清楚。
这是我的module.config.php
return array(
'controllers' => array(
'invokables' => array(
'ZFTickets\Controller\Index' => 'ZFTickets\Controller\IndexController',
),
),
'router' => array(
'routes' => array(
'zftickets' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
//'route' => '/zftickets',
'route' => '/',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'ZFTickets\Controller',
'controller' => 'Index',
//'controller' => 'ZFTickets\Controller\Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default when developing a module;
// as you solidify the routes for your module, however,
// you may want to remove it and replace it with more
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'zftickets' => __DIR__ . '/../view',
),
),
这是目录结构:
我得到的错误是:Zend \ View \ Renderer \ PhpRenderer :: render:无法渲染模板" zf-tickets / index / index&#34 ;;解析器无法解析为文件
答案 0 :(得分:6)
解析程序正在寻找zf-tickets/index/index
,但您已将文件夹创建为zftickets/zftickets/index
。改变这些,它应该工作正常。
您还应该将配置的视图管理器部分更改为:
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
数组键在那里是无关紧要的,所以你现在拥有的东西可能会让人感到困惑。
答案 1 :(得分:2)
ZF2的视图渲染器将尝试渲染.phtml
个相应匹配的控制器/操作名称文件,因为您没有提供自定义模板。尝试将第二个zftickets
文件夹重命名为您的控制器名称(在本例中为index
),如下所示:
|-- ...
|-- test
|-- view
| `-- zftickets
| `-- index
| `-- index.phtml
`-- autload_classmap.php