dongrendang6566 2012-09-21 05:41
浏览 10
已采纳

如何在zend框架2中使用特殊布局?

i have a bare bones zf2 application and i have 2 modules (Users and Album).

They both have their own layouts but i want to use the layout from Album for the Users, just to keep them a bit more consistent.

Im not sure what is the best way to delegate what layout a module should use.. from the controller __contruct, or on each individual action or in the module.config.php.

maybe here:

'template_map' => array(
        'layout/top_nav'        => __DIR__ . '/../view/layout/top_nav.phtml',
        'layout/layout'         => __DIR__ . '/../view/layout/layout.phtml', 

          ^^ probably i should set this path to the layout i want to use ^^

        'posts/index/index'     => __DIR__ . '/../view/posts/index/index.phtml',
        'error/404'             => __DIR__ . '/../view/error/404.phtml',
        'error/index'           => __DIR__ . '/../view/error/index.phtml',
    ),

any ideas? maybe the best practices?

thanks

edit: i just did this and it worked:

'layout/layout'         => __DIR__ . '/../../album /view/layout/layout.phtml',

but i'm still not sure if this is best practice.

maybe i can setup multiple template_map arrays and use them in the User controller, in my case

  • 写回答

1条回答 默认 最新

  • douxian9060 2012-09-21 06:19
    关注

    Edit: removed my own bullshit, just see the alternative approach :) That works

    Alternative approach

    Evan Coury also made the effor to have the Layout configuration globally available. This is especially true for single developers who won't make their modules public, ever. You will find his EdpModuleLayouts Module right here.

    Using that module switching layouts becomes even simpler like the following:

    <?php
    array(
        'module_layouts' => array(
            'ModuleName' => 'layout/some-layout',
        ),
    );
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用