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:
doctype('XHTML1_STRICT') ?>
partial('leftcolumn.phtml') ?> | layout()->content ?> < /div> |
In addition to layout.phtml, you also need to write header.phtml, leftcolumn.phtml, footer.phtml, and main.css and other documents.
The documentation of Zend Framework 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:
/**Setuplayout*/
require_once 'Zend/Layout.php' ;
Zend_Layout::startMvc($rootPath . '/application/views/layouts');
Note: After starting the page layout, you need to adjust the existing pages and remove unnecessary html elements, such as
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 a control All actions of the controller 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('new_layout');
}
The above is the introduction to Zend Framework (4) - page layout. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!