The CI framework uses layout to enrich the display elements of the view layer _php tutorial

Source: Internet
Author: User
Generally in the development process of the website, there will be a template or layout, it contains the entire site's appearance and layout, generally divided into header,content,footer some even include menu. The content section will vary depending on the page and function. This will ensure the consistency of Web site style, but also reduce a lot of work. Although the convenient codeigniter does not provide the built-in processing method, but we also expanded itself.

First, save the following code to application/libraries/layout.php

 
  obj =& get_instance ();         $this->layout = $layout;     }       function setlayout ($layout)     {       $this->layout = $layout;     }         Function view ($view, $data =null, $return =false)     {         $data [' content_for_layout '] = $this->obj->load- >view ($view, $data, true);                 if ($return)         {             $output = $this->obj->load->view ($this->layout, $data, true);             return $output;         }         else         {             $this->obj->load->view ($this->layout, $data, False);}}}     ?>

Load it into the relevant controller:

$this->load->library (' layout ');

You can output the PAGE down:

$data ["page_title"] = "Home for the guests"; $data ["Keywords"] = "internet, technology"; $data ["Description"] = "focus on internet technology"; $this->layout->view (' Support ', $data);

Our template or the file called layout (layout_main.php) is roughly as follows (simplified, there will be many sites fixed elements in the actual application):

      
 
   
 
      

The view that is loaded in the controller is "support" in the example. We just have to focus on the content of support. It fills in the template or the $content_for_layout part of the layout file and outputs it as a whole.

If, our template or layout does not want to call layout_main.php, such as to call template.php, then we will load the layout library to specify the name of the template, Specify in the second parameter (no PHP suffix required):

$this->load->library (' layout ', ' template ');

http://www.bkjia.com/PHPjc/752559.html www.bkjia.com true http://www.bkjia.com/PHPjc/752559.html techarticle generally in the development process of the website, there will be a template or layout, it contains the entire site's appearance and layout, generally divided into header,content,footer or even package ...

  • 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.