Home >Backend Development >PHP Tutorial >Zend Framework basic page layout analysis, zendframework_PHP tutorial
This article mainly introduces the basic page layout method of Zend Framework, and analyzes the basic steps and related setting techniques of Zend Framework page layout in the form of examples. Friends in need can refer to it
This article tells the example of Zend Framework basic page layout method. 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('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> <p id="header"> <?php echo $this->partial('header.phtml') ?> </p> <table> <tr> <td valign=top> <p id="leftcolumn"> <?php echo $this->partial('leftcolumn.phtml') ?> </p> </td> <td valign=top> <p id="content"> <?php echo $this->layout()->content ?> </p> </td> </tr> </table> <p id="footer"> <?php echo $this->partial('footer.phtml') ?> </p> </body> </html>
In addition to layout.phtml, you also need to write header.phtml, leftcolumn.phtml, and footer. phtml, and files such as main.css.
The Zend Framework documentation uses a view to represent the application of page layout.
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 'Zend/Layout.php'; Zend_Layout::startMvc($rootPath . '/application/views/layouts');
Note: After starting the page layout, you need to adjust each existing page and remove unnecessary html elements , such as 1aa9e5d373740b65a0cc8f0a02150c53 b2386ffb911b14667cb8f0f91ea547a7 6c04bd5ca3fcae76e30b72ad730ca86d etc. 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('new_layout');
If all actions of a controller use the same page layout, it can be set through the controller's initialization function:
public function init() { parent::init(); $this->_helper->layout->setLayout('new_layout'); }