2014-02-20 129 views
1

我想爲我的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

您是否爲您的控制器創建了索引視圖?我認爲它試圖渲染一個不存在的文件。 – thelastshadow

+0

是的。我剛剛編輯添加項目結構的文章。我很奇怪它正在尋找連字符分隔的路徑「online-field-evaluation/online-field-evaluation/index」 – vlr

+0

這就是默認模板解析器的工作原理。請參閱此處的文檔 - > http://framework.zend.com/manual/2.2/en/modules/zend.view.quick-start.html#controllers-and-view-models,特別是給出的「As舉例來說,具有動作「doSomethingCrazyAction」的控制器Foo \ Controller \ BazBatController將被映射到模板foo/baz-bat/do-something-crazy.'。相同的約定適用於模塊名稱。對於上面的例子,如果該模塊被命名爲'FooBar',模板路徑將是'foo-bar/baz-bat/do-something-crazy'。 – Crisp

回答

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 
+3

內部鍵是小寫而沒有特殊字符,所以這根本就不重要;)這只是他做錯了的視圖文件夾名稱。 – Sam

+0

奇怪的是,渲染器對視圖和src forders使用不同的命名約定。 – vlr