Zend Framework basic page layout analysis, zendframework
This article describes the basic page layout method of Zend Framework. We will share this with you for your reference. The details are as follows:
Zend_Layout, the page layout module of Zend Framework, can be used together with MVC or independently. This article only discusses the use of 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') ?>
In addition to layout. phtml, you also need to write header. phtml, leftcolumn. phtml, footer. phtml, main.css, and other files.
In Zend Framework documents, a view is used to represent the application of page layout.
2. Set the page layout
Setting the page layout in 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 the page layout is started, you must adjust the existing pages and remove unnecessary html elements, such as
It's easy to change the page layout. Just use the following code in the controller:
$this->_helper->layout->setLayout('new_layout');
If all the actions of a controller use the same page layout, you can set it through the initialization function of the controller:
public function init() {parent::init();$this->_helper->layout->setLayout('new_layout'); }