Zend Framework basic Page Layout Analysis _php instance

Source: Internet
Author: User
Tags getting started with php zend framework
This example describes the Zend Framework basic page Layout method. Share to everyone for your reference, as follows:

The Zend Framework's page layout module--zend_layout--can be used either with MVC or alone. This article discusses only the scenarios that are used with 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");//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, as well as files such as Main.css.
The Zend Framework document uses a single view to represent the application of the page layout.

2. Set Page layout

Setting the page layout under MVC is 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 starting the page layout, to adjust the existing pages, the unwanted HTML elements, such as

and so on. In addition, you can set the header of the page by $this->headtitle ().

Changing the layout of the page is also simple, just using the following code in the controller:

 $this->_helper->layout-
 >setlayout (' new_layout '); 

If a controller uses the same page layout for all actions, it can be set by the controller's initialization function:

public function init () {parent::init (); $this->_helper->layout-> SetLayout (' new_layout '); 

More readers interested in Zend related content can view this site topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory tutorial", " PHP Primer for object-oriented programming, "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Tips"

Hopefully this article will help you with PHP programming based on the Zend Framework framework.

  • Related Article

    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.