Apply a module layout to zfcuser

佐手、 提交于 2019-12-24 08:51:33

问题


i'm working on zf2 and try to use 2 differents layouts. 1 layout for a public module and another one (private layout") for all the others. Its works pretty well but my zfcuser module in the public module use the other layout :/ i tried this :

'template_map' => array(  
    'zfc-user/user/login' => __DIR__ . '/../view/layout/blank.phtml', // blank is my public layout 
),

Instead of get the form in my layout, i get my form in the public layout AND in the "private" layout ... Does someone can help me ?


回答1:


The code evan provides here http://blog.evan.pro/module-specific-layouts-in-zend-framework-2 will do what you need with one minor change, replace __NAMESPACE__ with 'ZfcUser' so that you're listening for ZfcUser controller actions

public function init(ModuleManager $moduleManager)
{
        $sharedEvents = $moduleManager->getEventManager()->getSharedManager();
        $sharedEvents->attach('ZfcUser', 'dispatch', function($e) {
        // This event will only be fired when an ActionController under the ZfcUser namespace is dispatched.
        $controller = $e->getTarget();
        $controller->layout('layout/alternativelayout');
    }, 100);
}



回答2:


Added to composer.json

"evandotpro/edp-module-layouts": "1.0"

Created /module/Application/view/layout/blank.phtml

<?php echo $this->content;

Added this to /config/autoload/global.php

return array(
'module_layouts' => array(
    'ZfcUser' => 'layout/blank'
));

Finally to /module/Application/config/module.config.php

'view_manager' => array(

    'template_map' => array(

        //add this line
        'layout/blank' => __DIR__ . '/../view/layout/blank.phtml',


来源:https://stackoverflow.com/questions/16054191/apply-a-module-layout-to-zfcuser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!