dtutlamjasblef7982 2010-02-28 18:20
浏览 87
已采纳

在我的.phtml文件中,我告诉它'使用'我创建的layout.phtml文件?

I'm kind of lost.

I made a sort of 'master page' that I want a page to use. Where do I declare it?

MainLayout.phtml

<html>
    <head>
    </head>
    <body>  
        <?php echo $this->layout()->content; ?>
        <div>
            <ul>        
                <li><a href="#">Navigation</a></li>
                <li><a href="#">Navigation</a></li>
                <li><a href="#">Navigation</a></li>
                <li><a href="#">Navigation</a></li>
                <li><a href="#">Navigation</a></li>
            </ul>
        </div>
    </body>
</html>

Index.phtml

<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <?php echo $this->headMeta() ?>
        <meta name="language" content="en" />
        <title><?php echo $this->escape($this->title) ?></title>
    </head>
    <body>
        <h1>This is the first page I made.</h1>

    </body>
</html>

I'm using the Zend framework.

  • 写回答

2条回答 默认 最新

  • dongmi1872 2010-02-28 18:50
    关注

    Basically, what Pascal said is correct: when Zend_Layout is used, it will insert the content of the view script into the master layout where

    echo $this->layout()->content;
    

    is called. Since it is an insertion, you do not include the entire HTML page though. In your example, the template and the layout both contain a full page with HTML, HEAD and BODY elements, resulting in invalid markup.

    However, since View Scripts are processed before Layout scripts, you can set the layout from the View script through the layout helper, using

    $this->layout()->setLayout('foo');
    

    You can also set the layout from the Controller

    $this->_helper->layout->disableLayout();
    

    And of course, like everything else in ZF, it is configurable from the application.ini as well. The Zend_Layout Quickstart is really best start to learn about this component.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大