To load a view within another view. We can also use the same method we used in the controller to load the "primary" view.
<?php $this->load->view('header');?><div><p>This is the content</p></div><?php $this->load->view('footer');?>
Some coders might desire not to put $this->load->view()
in the view. An alternative is to create a helper for loading views.
// load_view_helper.phpif ( ! function_exists('load_view')){function load_view($view, $vars = '', $return = FALSE){$CI =& get_instance();return $CI->load->view($view, $vars, $return);}}
Add this to the helper array:
$autoload['helper'] = array('load_view');
And you're all set! To use:
<?php load_view('header');?><div><p>This is the content</p></div><?php load_view('footer');?>
There are still tons of alternatives out there. One that is recommended is using Colin William's Template Library. Our example is one of the simplest.
联系客服