Pergunta

I need 2 different template maps in ZF2 , one for admin and oen for front-end, currently from what I can see ZF2 merges the 2 module.config.php files that are used in the 2 modules I configured, and causes the template map I need to set for the admin, to be loaded in front module also.

the /Application module.config.php

...
'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',
        ),
...

the /admin module.config.php

...
'view_manager' => array(
        'template_path_stack' => array(
            'admin' => __DIR__ . '/../view',
        ),
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        ),
    ),
...

what should I modify so that i can load separate "view_manager" arrays for the 2 separate modules ?

Foi útil?

Solução

It would be great if you can explain why you are trying to achieve this. As i can see you are trying to have a different layout for admin. Maybe you want to take a look at this module which can already do what you are trying https://github.com/zf-commons/zfcadmin. This module has a layut setup for the admin route.

Outras dicas

I too had this problem. I took the approach which is proposed in the below module

https://github.com/EvanDotPro/EdpModuleLayouts

I'm new to ZF2 and I too was looking for an answer on how to have a completely different template for a dashboard, admin and front end.

I used EdpModuleLayouts as suggested here and in many other posts. This solved one aspect of the problem. The layout. I was now able to provide different layouts for the same template which would work well if I were using the same template or wanted to prove a different layout for say forgotten password, registration or a login. But I didn't. I needed a whole different set of folders, css files etc. At this point I could have just nested all templates in to a template folder and pointed the links in the layout files to the appropriate folders. But I didn't want this either.

I also included the zfc-admin module into my app which gave me a clue as to the other aspect which is to provide a different source directly for files. (Uninstalled afterward)

So adding by adding the following to my module_name/config/module.config.php

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

Enabling EdpModuleLayouts in application.config.php and adding the code below to the Application module.config.php

'module_layouts' => array(
    'Application' => 'layout/layout',
    'Dashboard' => 'layout/dashboard',
    'Admin' => 'layout/admin',
),

This is probably not the best way to do it but it worked. The only issue I could really see with doing it this way is that EdpModuleLayouts wants to pull all the layouts from the Application/view/layout folder. It did however allow me to keep all my module template files in the view section of the module being worked on.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top