layoutzend-framework2zfcuser

Apply a module layout to zfcuser


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 ?


Solution

  • 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);
    }