Question

I want to make automatic match view file - controller action.

If /Web/TestController/testAction (module/controller/action) requested,

ZF2 tries to load this view : /web/test/test

Then, I have to add this line to template_map to make It work :

'web/test/test'     => __DIR__ . '/../view/pages/test/test.phtml',

But I don't want to add this lines for all actions.

Can it work like this :

'web/{ABC}/{XYZ}'     => __DIR__ . '/../view/pages/{ABC}/{XYZ}.phtml',

how do i make it so that it would automatically matches ?

module.config.php :

return array(
    'router' => array(
        'routes' => array(
            'web' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '[/:action]',
                    'constraints' => array(),
                    'defaults' => array(
                        'controller' => 'Web\Controller\Test',
                    ),
                )
            )
        )
    ),


    '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/test'       => __DIR__ . '/../view/layouts/test/test.phtml',
            'layout/default'    => __DIR__ . '/../view/layouts/default/default.phtml',
            'error/404'         => __DIR__ . '/../view/error/404.phtml',
            'error/index'       => __DIR__ . '/../view/error/index.phtml',

            'web/test/test'     => __DIR__ . '/../view/pages/test/test.phtml',
        ),

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

        'layout'                    => 'layout/default'
    ),
);
Was it helpful?

Solution

You should rename the "pages" directory to "web" and change the config file as follows

'web/test/test'     => __DIR__ . '/../view/web/test/test.phtml',
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top