Best way to load header and footer once globally? |
I would suggest to make MY_Loader.php in application/core folder. That automagically extends load method and you don't need to extend any controller.
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class MY_Loader extends CI_Loader { function __construct() { parent::__construct(); $CI =& get_instance(); $CI->load = $this; } // this is used in cms public function template($template_name, $vars = array(), $return = TRUE){ $content = $this->view('header', $vars, $return); $content .= $this->view('leftpanel', $vars, $return); $content .= $this->view('rightpanel', $vars, $return); if(is_array($template_name)) { //return all values in contents foreach($template_name as $file_to_load) { $content .= $this->view($file_to_load, $vars, $return); } }else{ $content .= $this->view($template_name, $vars, $return); } $content .= $this->view('footer', $vars, $return); echo $content; } } Then call it from controller like this: $this->load->template('dashboard', $data); And you can use multiple templates using array like: $this->load->template(['dashboard', 'bottom_content'], $data); |
Messages In This Thread |
Best way to load header and footer once globally? - by HarrysR - 09-28-2018, 07:29 AM
RE: Best way to load header and footer once globally? - by Wouter60 - 09-28-2018, 09:43 AM
RE: Best way to load header and footer once globally? - by HarrysR - 10-02-2018, 07:27 AM
RE: Best way to load header and footer once globally? - by imabot - 10-04-2018, 08:48 AM
RE: Best way to load header and footer once globally? - by ignitedcms - 10-04-2018, 09:26 AM
RE: Best way to load header and footer once globally? - by HarrysR - 10-04-2018, 09:44 AM
RE: Best way to load header and footer once globally? - by davis.lasis - 10-04-2018, 10:37 AM
RE: Best way to load header and footer once globally? - by sintakonte - 10-08-2018, 11:00 PM
RE: Best way to load header and footer once globally? - by HarrysR - 10-09-2018, 04:42 AM
|