Question

Starting a new project with the skeleton module and I'm running into some issues. I'm sure this is a basic config error on my part, but I can't figure it out.

Here is my module.config.php

return array(
    'controllers' => array(
        'invokables' => array(
            'ZFTickets\Controller\Index' => 'ZFTickets\Controller\IndexController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'zftickets' => array(
                'type'    => 'Literal',
                'options' => array(
                    // Change this to something specific to your module
                    //'route'    => '/zftickets',
                    'route'    => '/',
                    'defaults' => array(
                        // Change this value to reflect the namespace in which
                        // the controllers for your module are found
                        '__NAMESPACE__' => 'ZFTickets\Controller',
                        'controller'    => 'Index',
                        //'controller'    => 'ZFTickets\Controller\Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    // This route is a sane default when developing a module;
                    // as you solidify the routes for your module, however,
                    // you may want to remove it and replace it with more
                    // specific routes.
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'zftickets' => __DIR__ . '/../view',
        ),
    ),

and here is the directory structure: enter image description here

The error I get is: Zend\View\Renderer\PhpRenderer::render: Unable to render template "zf-tickets/index/index"; resolver could not resolve to a file

Was it helpful?

Solution

The resolver is looking for zf-tickets/index/index, but you're created the folders as zftickets/zftickets/index. Change these and it should work fine.

You should also change the view manager part of your config to:

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

The array key is irrelevant there, so what you currently have might appear confusing.

OTHER TIPS

ZF2's view renderer will try to render .phtml files accordingly matched controller/action names since you don't provide a custom template. Try to rename second zftickets folder to your controller name (in this case: index) like this:

|-- ...
|-- test
|-- view
|    `-- zftickets
|        `-- index
|            `-- index.phtml
`-- autload_classmap.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top