应用模块布局zfcuser(Apply a module layout to zfcuser)

2019-10-18 01:30发布

我工作的ZF2,并尝试使用2个型动物布局。 1个布局公共模块和另外一个(私人布局“)的所有其他它工作得很好,但公众模块在我zfcuser模块用其他的布局:/我想这:

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

相反,在得到我的布局形式,让我的公共布局,并在“私”的布局形式...是否有人能帮助我吗?

Answer 1:

该代码埃文提供这里http://blog.evan.pro/module-specific-layouts-in-zend-framework-2会做你所需要的一个小的改动,更换__NAMESPACE__'ZfcUser'让你在听对于ZfcUser控制器操作

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


Answer 2:

加入composer.json

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

创建/module/Application/view/layout/blank.phtml

<?php echo $this->content;

添加到了/config/autoload/global.php

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

终于到/module/Application/config/module.config.php

'view_manager' => array(

    'template_map' => array(

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


文章来源: Apply a module layout to zfcuser