Home  >  Article  >  php教程  >  Zend Framework basic page layout analysis

Zend Framework basic page layout analysis

高洛峰
高洛峰Original
2017-01-05 10:58:501569browse

The example in this article describes the basic page layout method of Zend Framework. Share it with everyone for your reference, the details are as follows:

Zend Framework’s page layout module—Zend_Layout—can be used together with MVC or alone. This article only discusses use with MVC.

1. Layout script

Create a layouts folder under application/views. The main layout script layout.phtml code is as follows:

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

In addition to layout.phtml, you also need to write header.phtml, leftcolumn.phtml, footer.phtml, and main.css files.
The documentation of Zend Framework uses a view to represent the application of page layout.

Zend Framework基本页面布局分析

2. Set the page layout

Setting the page layout under MVC is very simple. Edit html/index.php and add the following two lines of code:

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

Note: After starting the page layout, adjust the existing pages and remove unnecessary html elements, such as 1aa9e5d373740b65a0cc8f0a02150c53 b2386ffb911b14667cb8f0f91ea547a7 < ;body> and so on are removed. In addition, you can set the title of the page through $this->headTitle().

Changing the layout of the page is also very simple, just use the following code in the controller:

$this->_helper->layout->setLayout(&#39;new_layout&#39;);

If a controller All actions use the same page layout, which can be set through the initialization function of the controller:

public function init() {
parent::init();
$this->_helper->layout->setLayout(&#39;new_layout&#39;);
}

I hope that this article will help everyone use PHP based on the Zend Framework framework. Programming helps.

For more articles related to Zend Framework basic page layout analysis, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn