zend framework怎麼使用布局

來源:互聯網
上載者:User
zend framework如何使用布局
最好執行個體講解,手冊看了不太懂
比如說我要實現




layout->content ?>



要使用布局是不是要先進行什麼配置?這裡要如何替換top、main、footer的內容?content的內容在哪裡賦值?

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

1. 布局指令碼

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

doctype('XHTML1_STRICT') ?>



headTitle() ?>
$this->headLink()->appendStylesheet("/styles/main.css");
// add more links ...
?>
headLink() ?>



partial('header.phtml') ?>








partial('leftcolumn.phtml') ?>



layout()->content ?>



partial('footer.phtml') ?>





除了 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 元素,如 <body> 等去掉。另外,可以通過 $this->headTitle() 來設定頁面的題頭。<br /><br />改變頁面的布局也很簡單,只需在控制器中用下面的代碼即可:<br /><br />$this->_helper->layout->setLayout('new_layout');<br /><br />如果一個控制器所有動作都使用同一個頁面配置,可以通過控制器的初始化函數來設定:<br /><br />public function init() {<br />parent::init();<br /><br />$this->_helper->layout->setLayout('new_layout'); <br />}<br /> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />------------------------------------------------------------<br />http://www.jiemengwu.com/ 解夢屋 http://www.phpzy.com/php/ 綠色php資源http://www.shopfw.com網店服務<br />------解決方案--------------------<br /><fieldset><legend>探討</legend><br />最好執行個體講解,手冊看了不太懂<br />比如說我要實現<br /><html><br /><head><title>


layout->content ?>



要使用布局……

------解決方案--------------------
探討
$this->partial('header.phtml')
partial('leftcolumn.phtml') ?>
這裡的header.phtml和leftcolumn.phtml要放在和layout.phtml同一層目錄下嗎
裡面如何使用controller賦值的變數
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.