无法渲染 - 解析程序无法解析为文件

时间:2014-02-20 00:51:01

标签: php zend-framework2

我正在尝试为Zend项目设置模块结构,这是我遇到的错误。我不明白为什么Renderer在寻找这条路径“在线现场评估/在线评估/索引”。 Zend中的Camel表示法有问题吗?感谢。

Zend\View\Exception\RuntimeException

File:

    C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php:499

Message:

    Zend\View\Renderer\PhpRenderer::render: Unable to render template "online-field-evaluation/online-field-evaluation/index"; resolver could not resolve to a file

Stack trace:

    #0 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\View\View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
    #1 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\View\View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
    #2 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\View\View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
    #3 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
    #4 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
    #5 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(471): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
    #6 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)
    #7 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(347): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent))
    #8 C:\dev\xampp\htdocs\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(322): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
    #9 C:\dev\xampp\htdocs\OnlineFieldEvaluation\public\index.php(25): Zend\Mvc\Application->run()
    #10 {main}

这是我的module.config.php:

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'OnlineFieldEvaluation\Controller\OnlineFieldEvaluation' => 'OnlineFieldEvaluation\Controller\OnlineFieldEvaluationController',
        ),
    ),

    // The following section is new and should be added to your file
    'router' => array(
            'routes' => array(
                    'onlinefieldevaluation' => array(
                            'type'    => 'segment',
                            'options' => array(
                                    'route'    => '/onlinefieldevaluation[/][:action][/:id]',
                                    'constraints' => array(
                                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                            'id'     => '[0-9]+',
                                    ),
                                    'defaults' => array(
                                            'controller' => 'onlinefieldevaluation\Controller\onlinefieldevaluation',
                                            'action'     => 'index',
                                    ),
                            ),
                    ),
            ),
    ),      
    'view_manager' => array(
        'template_path_stack' => array(
            'onlinefieldevaluation' => __DIR__ . '/../view',
        ),
    ),
);

这是我的Module.php

<?php

namespace OnlineFieldEvaluation;

class Module
{
    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }
}

**编辑1:这是我项目结构的图像:**

enter image description here

1 个答案:

答案 0 :(得分:5)

在您编写的config.php上

    'invokables' => array(
        'OnlineFieldEvaluation\Controller\OnlineFieldEvaluation' => 'OnlineFieldEvaluation\Controller\OnlineFieldEvaluationController',
    ),

但你打电话

'defaults' => array(
       'controller' => 'onlinefieldevaluation\Controller\onlinefieldevaluation',
       'action'     => 'index',
),

由此改变

'defaults' => array(
       'controller' => 'OnlineFieldEvaluation\Controller\OnlineFieldEvaluation',
       'action'     => 'index',
),

并将视图脚本的文件夹名称更改为小写,如

view
  online-field-evaluation
     online-field-evaluation
相关问题