Wige
Wige

Reputation: 3918

PHP Zend Framework 2 - Renderer is looking for the template in an unexpected folder

I have created a new module in my ZF2 installation called AB2CD. The indexAction of IndexController only returns a new ViewModel(). The error message I am getting is:

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

My view manager in module.config.php is:

'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
    'doctype'                  => 'HTML5',
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index',
    'template_map' => array(
        'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ),
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
),

Where would it be coming up with the folder ab2-cd? I could resolve the error by renaming the folder, but I'm hoping to understand why it is looking in the wrong place to start with...

Upvotes: 0

Views: 243

Answers (2)

cptnk
cptnk

Reputation: 2420

In addition to Exlord's answer you do not have to manually set the template in your controller you could also provide a template map within your module.config.php

'view_manager' => array(
   ...
   'template_map' => array(
      'ab2-cd/index/index' => __DIR__ . '/../view/AB2CD/index/index.phtml',
   ),
   ...
),

I also would advise against using module names with numbers in it. Something like AbToCd which would translate to ab-to-cd/index/index would work better with the psr-0.

Upvotes: 1

Exlord
Exlord

Reputation: 5371

ab2-cd is generated from your modules name AB2CD. if you don't what a auto generated name provide the template name for the view model manually with setTemplate method.

if you want to keep using the auto generated names , your directory structure should be something like :

--module
 |--AB2CD
   |--view
     |--ab2-cd
       |--[lower-cased-controller-name]
         |--[lower-cased-action-name]

Upvotes: 2

Related Questions