Zend Framework,PhpRenderer 无法呈现模板将控制器添加到模板名称中
Zend Framework, PhpRenderer unable to render template adds controllers into the template name
我从 ZF2 迁移到 ZF3。现在我有一个问题。我的视图脚本在正确的位置,配置似乎没问题,但出现以下错误:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "parties/controllers/write-party/add"; resolver could not resolve to a file
这是一个相当常见的错误,但问题是由于某种原因,我在模板路径中得到了 controllers
文件夹。模板路径应为 parties/write-party/add
。
module.config.php
return [
'controllers' => [
'factories' => [
WritePartyController::class => WritePartyControllerFactory::class,
],
],
'router' => [
'routes' => [
'parties' => [
'type' => Literal::class,
'options' => [
'route' => '/parties',
'defaults' => [
'__NAMESPACE__' => 'Parties\Controllers',
'controller' => 'Index',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'add' => [
'type' => Segment::class,
'options' => [
'route' => '/add',
'defaults' => [
'controller' => WritePartyController::class,
'action' => 'add',
],
],
],
//...
'view_manager' => [
'template_path_stack' => [
'parties' => __DIR__ . '/../view',
],
'strategies' => [
'ViewJsonStrategy',
],
],
],
如何获得我的视图脚本的正确路径 parties/write-party/add
?
事实证明这个问题比我想象的要复杂。在 ZF3 内部,假定包含模块控制器的文件夹名为 Controller
(单数)。如果不是这种情况,它会让命名空间 YourModule/Controllers/ControllersName/
转移到路径 your-module/controllers/controllers-name/
,这就是我所看到的。所有这一切都发生在 InjectTemplateListener
的 mapController
方法中。所以我猜这是一个错误,因为 ZF2 没有问题。
我从 ZF2 迁移到 ZF3。现在我有一个问题。我的视图脚本在正确的位置,配置似乎没问题,但出现以下错误:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "parties/controllers/write-party/add"; resolver could not resolve to a file
这是一个相当常见的错误,但问题是由于某种原因,我在模板路径中得到了 controllers
文件夹。模板路径应为 parties/write-party/add
。
module.config.php
return [
'controllers' => [
'factories' => [
WritePartyController::class => WritePartyControllerFactory::class,
],
],
'router' => [
'routes' => [
'parties' => [
'type' => Literal::class,
'options' => [
'route' => '/parties',
'defaults' => [
'__NAMESPACE__' => 'Parties\Controllers',
'controller' => 'Index',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'add' => [
'type' => Segment::class,
'options' => [
'route' => '/add',
'defaults' => [
'controller' => WritePartyController::class,
'action' => 'add',
],
],
],
//...
'view_manager' => [
'template_path_stack' => [
'parties' => __DIR__ . '/../view',
],
'strategies' => [
'ViewJsonStrategy',
],
],
],
如何获得我的视图脚本的正确路径 parties/write-party/add
?
事实证明这个问题比我想象的要复杂。在 ZF3 内部,假定包含模块控制器的文件夹名为 Controller
(单数)。如果不是这种情况,它会让命名空间 YourModule/Controllers/ControllersName/
转移到路径 your-module/controllers/controllers-name/
,这就是我所看到的。所有这一切都发生在 InjectTemplateListener
的 mapController
方法中。所以我猜这是一个错误,因为 ZF2 没有问题。