How to use zendframework layout

Source: Internet
Author: User
Zendframework provides an example of how to use the best layout. the manual does not quite understand how to implement it. for example, I want to implement & lt; html & gt; & lt; head & gt; & lt; title & gt; & lt;/title & gt; & lt;/head & gt; & lt; body & gt; & lt; divid = & quot; top & q zend framework
It is best to explain the examples. I have not understood the manual.
For example




Layout-> content?>



Do you need to configure the layout first? How can I replace top, main, and footer content? Where is the content assigned?

------ Solution --------------------
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:

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:

/** Setup layout */
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 <Body> and so on. In addition, you can set the header of the page through $ this-> headTitle. <Br/> It is easy to change the page layout. you only need to use the following code in the controller: <br/> $ this-> _ helper-> layout-> setLayout ('New _ layout '); <br/> if all the actions of a controller use the same page layout, you can set it through the initialization function of the controller: <br/> public function init () {<br/> parent: init (); <br/> $ this-> _ helper-> layout-> setLayout ('New _ layout '); <br/>}< br/> <br/>/> <br/> http://www.jiemengwu.com/dream house http://www.phpzy.com/php/ green php resources http://www.shopfw.com online shop service <br/> ------ solution ------------------ <br/> <fieldset> <legend> Discussion </legend> <br/> It is best to explain the examples, I don't know much about the manual. <br/> For example, I want to implement it. <br/> <ptml> <br/> <pead> <title>


Layout-> content?>



Use layout ......

------ Solution --------------------
Discussion
$ This-> partial ('header. phpml ')
Partial ('leftcolumn. phpml')?>
Should header. phtml and leftcolumn. phtml be placed in the same directory as layout. phtml?
How to use the variable assigned by the controller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.