Zend_Layout, the page layout module of ZendFramework, can be used together with MVC or independently. This article only discusses the use of MVC. 1. the layout script creates a layouts folder under applicationviews. The code of the main layout script layout. phtml is as follows: & lt ;? Phpecho $ this-& gt; Page Layout module of the doct Zend Framework -- Zend_Layout -- can be used together with MVC or separately. 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:
Doctype ('xhtml1 _ STRICT ')?>
HeadTitle ()?>
$ This-> headLink ()-> appendStylesheet ("/styles/main. CSS ");
// Add more links...
?>
HeadLink ()?>
Partial ('header. phpml')?>
Partial ('leftcolumn. phpml')?>
|
Layout ()-> content?>
|
Partial ('footer. phtml')?>
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:
/** Setuplayout */
Require_once 'zend/Layout. php ';
Zend_Layout: startMvc ($ rootPath. '/application/views/layouts ');
Note: after the page layout is started, you need to adjust the existing pages and add unnecessary html elements, such
And so on. In addition, you can set the header of the page through $ this-> headTitle.
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 ');
}