ZF2“无法呈现模板”Zend查找错误的目录

时间:2013-07-26 13:10:58

标签: php zend-framework2

我有一种奇怪的情况......

在创建ZF2 SkeletonApplication之后,我在视图目录“authentication / auth”中创建了一个名为Authentication的额外模块,其中包含AuthController和LoginAction,我放置了一个login.phtml。

当我运行应用程序时出现错误

Zend\View\Renderer\PhpRenderer::render: Unable to render template "authentication/auth/login"; resolver could not resolve to a file

奇怪的是,当我在标准应用程序模块视图文件夹中放置完整文件夹“authentication / auth / login.phtml”时,它会找到它。

所以Zend正在寻找错误的目录。

这是我的module.config.php(验证模块)。

return array(
'router' => array(
    'routes' => array(
        'authentication' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/authentication/login',
                'defaults' => array(
                    'controller' => 'Authentication\Controller\Auth',
                    'action'     => 'login',
                ),
            ),
        ),
    ),
),
'controllers' => array(
    'invokables' => array(
        'Authentication\Controller\Auth' => 'Authentication\Controller\AuthController',
    ),
),
'viewmanager' => array(
    'template_path_stack' => array(
        'authentication' => __DIR__ . '/../view',
    ),
    )
);

这是AuthController

namespace Authentication\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class AuthController extends AbstractActionController
{
    public function loginAction()
    {
        return new ViewModel();
    }
}

我希望有人能指出我正确的方向。

2 个答案:

答案 0 :(得分:4)

zf2无法解析完整路径。 viewManager使用模板pathStack查找相对视图。在您的示例中,viewManager正在查找此文件:      DIR 。 “/../视图/认证/ AUTH / login.phtml

另外,您可以在viewManager中添加如下模板地图:

'view_manager' => array(
    'template_map' => array(
        'authentication/auth/login' => __DIR__ . '/../view/where/you/want.phtml',
     )
 );

答案 1 :(得分:2)

更改您的配置:

'template_path_stack' => array(
    'authentication' => __DIR__ . '/../view',
),

我猜你的水平太远了......

如果你在这里配置:

Authentication/config/module.config.php

然后你只想回到一个级别,然后进入你的视图目录。您的代码会将您带回更高级别的模块目录。