Heim  >  Artikel  >  Backend-Entwicklung  >  Zend Framework之Layout

Zend Framework之Layout

巴扎黑
巴扎黑Original
2016-11-10 11:03:41854Durchsuche

为了让不同的View以相同的布局进行显示,我们可以编写布局模板文件,并以layout.phtml为名称进行保存,并在Index.php中指定这个文件所在的位置。

require_once'Zend/Layout.php';

Zend_Layout::startMvc(array('layoutPath'=>'../application/default/layouts'));

在布局文件中,我们可以指定网页需要使用的样式文件,JavaScript脚本文件。

<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<?php
$request=Zend_Controller_Front::getInstance()->getRequest();
$this->headTitle(&#39;视图中使用视图&#39;)
->headTitle($request->getModuleName())
->headTitle($request->getActionName())
->headTitle($request->getControllerName())
->setSeparator(&#39;|&#39;);
echo$this->headTitle();
$this->headLink()->appendStylesheet($this->baseUrl."/css/style.css")
->appendStylesheet($this->baseUrl."/css/demo.css");
echo$this->headLink();
$this->headScript()->appendFile($this->baseUrl."/js/jquery-1.2.6.js")
->appendFile($this->baseUrl."/js/jquery.datePicker.js")
->appendFile($this->baseUrl."/js/demo.js");
echo$this->headScript();
?>
</head>
<body>
<divid=&#39;bodywrapper&#39;>
<divid=&#39;header&#39;>
<?phpecho$this->partial(&#39;header.phtml&#39;,&#39;default&#39;);?>
</div>
<divid=&#39;sidebar&#39;>
<?phpecho$this->partial(&#39;leftside.phtml&#39;,&#39;default&#39;);?>
</div>
<divid=&#39;midcontent&#39;>
<?phpecho$this->layout()->content;?>
</div>
<divid=&#39;footer&#39;>
<?phpecho$this->partial(&#39;footer.phtml&#39;,&#39;default&#39;);?>
</div>
</div>
</body>
</html>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP调用MS SQL 存储过程Nächster Artikel:PHP日期操作