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