1

I am trying to setup module structure for my Zend project, and this is an error I am getting. I do not understand why Renderer looking for this path "online-field-evaluation/online-field-evaluation/index" . Is there some problem with Camel notation in Zend ? Thanks.

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}

Here is my 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',
        ),
    ),
);

And here is my 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__,
                ),
            ),
        );
    }
}

**EDIT 1: here is the image of my project structure : **

enter image description here

3
  • 1
    Have you created an index view for your controller? I think it's trying to render a file that doesn't exist. Feb 20, 2014 at 0:53
  • Yes. I just edited the post adding the project structure. It is strange for me that it is looking for hyphen separated path "online-field-evaluation/online-field-evaluation/index"
    – vlr
    Feb 20, 2014 at 1:02
  • That's how the default template resolver works. See the docs here -> framework.zend.com/manual/2.2/en/modules/… and in particular the example given of As an example, the controller Foo\Controller\BazBatController with action “doSomethingCrazyAction”, would be mapped to the template foo/baz-bat/do-something-crazy.. The same convention applies to the module name. For the above example if the module had been named FooBar the template path would be foo-bar/baz-bat/do-something-crazy.
    – Crisp
    Feb 20, 2014 at 2:18

1 Answer 1

5

on your config.php you wrote

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

But you call

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

change by this

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

and change the folders names of your view script to lowercase like

view
  online-field-evaluation
     online-field-evaluation
2
  • 3
    internally keys are lowercased without special chars, so that wouldn't even matter ;) It's just the view-folder-names that he did wrong.
    – Sam
    Feb 20, 2014 at 6:42
  • Strange that renderer is using different naming convention for the view and src forders.
    – vlr
    Feb 20, 2014 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.