国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Zend Framework 入門(4)—頁面布局

2019-11-17 04:23:34
字體:
來源:轉載
供稿:網友

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>
<div id="header">
<?php echo $this->partial('header.phtml') ?>
</div>
<table>
<tr>
<td valign=top>
<div id="leftcolumn">
<?php echo $this->partial('leftcolumn.phtml') ?>
</div>
</td>
<td valign=top>
<div id="content">
<?php echo $this->layout()->content ?>
</div>
</td>
</tr>
</table>
<div id="footer">
<?php echo $this->partial('footer.phtml') ?>
</div>
</body>
</html>

除了layout.phtml 之外,還需要編寫 header.phtml,leftcolumn.phtml,footer.phtml,以及 main.css 等文件。

Zend Framework 的文檔中用一個視圖表示了頁面布局的應用。

2. 設置頁面布局

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

/** Setuplayout*/
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');
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德保县| 略阳县| 陕西省| 四子王旗| 扶绥县| 洛宁县| 马边| 洪江市| 来宾市| 九寨沟县| 汤原县| 开化县| 老河口市| 广东省| 珠海市| 扬中市| 沙雅县| 手机| 洪湖市| 商河县| 阳原县| 建湖县| 遂昌县| 平南县| 鹰潭市| 如皋市| 梨树县| 星子县| 台北县| 临桂县| 崇礼县| 博客| 乌兰察布市| 古蔺县| 福泉市| 高雄市| 萨迦县| 铁岭市| 望奎县| 报价| 武陟县|