源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Zend Framework基本页面布局分析

  • 时间:2020-09-02 12:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Zend Framework基本页面布局分析
本文实例讲述了Zend Framework基本页面布局方法。分享给大家供大家参考,具体如下: Zend Framework 的页面布局模块——Zend_Layout——既可以跟 MVC 一起使用,也可以单独使用。本文只讨论与 MVC 一起使用的情况。 [b]1、布局脚本[/b] 在 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 的文档中用一个视图表示了页面布局的应用。 [img]http://files.jb51.net/file_images/article/201603/2016319114656893.jpg?2016219115141[/img] [b]2、设置页面布局[/b] 在 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'); 
}

更多关于zend相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/546.htm]Zend FrameWork框架入门教程[/url]》、《[url=http://www.1sucai.cn/Special/155.htm]php优秀开发框架总结[/url]》、《[url=http://www.1sucai.cn/Special/386.htm]Yii框架入门及常用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/39.htm]ThinkPHP入门教程[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部