Zend Framework基本頁面布局分析,zendframework_PHP教程

來源:互聯網
上載者:User
這篇文章主要介紹了Zend Framework基本頁面布局方法,結合執行個體形式分析了Zend Framework頁面配置的基本步驟與相關設定技巧,需要的朋友可以參考下

本文執行個體講述了Zend Framework基本頁面布局方法。分享給大家供大家參考,具體如下:

Zend Framework 的頁面配置模組——Zend_Layout——既可以跟 MVC 一起使用,也可以單獨使用。本文只討論與 MVC 一起使用的情況。

1、布局指令碼

在 application/views 下建立一個 layouts 的檔案夾。主布局指令碼 layout.phtml 代碼如下:

<?php echo $this->doctype('XHTML1_STRICT') ?><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><?php echo $this->headTitle() ?><?php$this->headLink()->appendStylesheet("/styles/main.css");// add more links ...?><?php echo $this->headLink() ?></head><body><p id="header"><?php echo $this->partial('header.phtml') ?></p><table><tr><td valign=top><p id="leftcolumn"><?php echo $this->partial('leftcolumn.phtml') ?></p></td><td valign=top><p id="content"><?php echo $this->layout()->content ?></p></td></tr></table><p id="footer"><?php echo $this->partial('footer.phtml') ?></p></body></html>

除了 layout.phtml 之外,還需要編寫 header.phtml,leftcolumn.phtml,footer.phtml,以及 main.css 等檔案。
Zend Framework 的文檔中用一個視圖表示了頁面配置的應用。

2、設定頁面配置

在 MVC 下設定頁面配置非常簡單,編輯 html/index.php,加入下面兩行代碼:

/** Setup layout */require_once 'Zend/Layout.php';Zend_Layout::startMvc($rootPath . '/application/views/layouts');

注意:在啟動頁面配置後,要調整已有的各個頁面,把不需要的 html 元素,如<header> <title> <body> 等去掉。另外,可以通過 $this->headTitle() 來設定頁面的題頭。

改變頁面的布局也很簡單,只需在控制器中用下面的代碼即可:

$this->_helper->layout->setLayout('new_layout');

如果一個控制器所有動作都使用同一個頁面配置,可以通過控制器的初始化函數來設定:

public function init() {parent::init();$this->_helper->layout->setLayout('new_layout'); }
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.