问题
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