In web development, some modules are usually public, such as header, footer, and menu. layout uses the public part as a template, which not only reduces the workload, but also facilitates later maintenance. (I wrote an article about ZendFramework.
In web development, some modules are usually public, such as header, footer, and menu. layout uses the public part as a template, which not only reduces the workload, but also facilitates later maintenance. (I wrote an article about Zend Framework Implementation Layout ).
The CI framework has many Layout functions. one of the following is described:
1. create the directory _ layouts under the View views directory to store the layout file.
2. libraries New extension Layout. php:
obj =& get_instance(); $this->layout = '_layouts/' . $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); } } } ?>
3. note: By default, member is used as layout. Therefore, in _ layouts, create the layout view file member. php:
This is the layout of member.
4. use the following in controller:
Class Welcome extends CI_Controller {public function _ construct () {parent ::__ construct (); $ this-> load-> library ('layout ');} public function test_layout () {$ data ['test'] = 'this is a PHP point-to-point test tutorial'; $ this-> layout-> view ('content ', $ data );}}
5. create content. php in views as follows:
This is content
The directory structure is as follows: