ZendFramework basic page layout analysis _ php instance

Source: Internet
Author: User
Tags zend framework
This article mainly introduces the basic page layout method of ZendFramework, and analyzes the basic steps and related settings of ZendFramework page layout in the form of instances, for more information about Zend Framework basic page layout, see the following example. 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') ?>
 <?php echo $this->headTitle() ?><?php$this->headLink()->appendStylesheet("/styles/main.css?6.1.3");// add more links ...?><?php echo $this->headLink() ?>

<?php echo $this->partial('header.phtml') ?>

<?php echo $this->partial('leftcolumn.phtml') ?>

<?php echo $this->layout()->content ?>

<?php echo $this->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

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'); }

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.