我在Zend Framework 2项目中出错,我尝试添加一个名为“ Blog”的新视图
我创建了module.config和indexController以及视图,但是总是出现此错误,我也不知道为什么:
Zend \ View \ Renderer \ PhpRenderer :: render:无法渲染模板 “博客/索引/索引”;解析器无法解析为文件
module.config代码
<?php
namespace Blog;
return array(
'router' => array(
'routes' => array(
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /blog/:controller/:action
'blog' => array(
'type' => 'Literal',
'options' => array(
'route' => '/blog',
'defaults' => array(
'__NAMESPACE__' => 'Blog\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
),
),
),
),
),
),
),
'controllers' => array(
'invokables' => array(
//'Blog\Controller\Index' => 'Blog\Controller\IndexController'
'Blog\Controller\Index' => Controller\IndexController::class
),
),
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
?>
indexController代码:
<?php
namespace Blog\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
return new ViewModel();
}
}
?>
最后我的结构文件夹是这样的:
我使用版本2.4.13
答案 0 :(得分:3)
src
文件夹应仅包含PHP类,视图模板不应位于其中。将视图文件夹上移,它应该可以工作。
以ZF骨架应用程序的文件夹结构为参考:https://github.com/zendframework/ZendSkeletonApplication/tree/master/module/Application