I\'m new in CodeIgniter. I want to create Master Page or Layout with base style that will be contain Menu, footer and etc. I don\'t want to write repeating content in all pa
You would create a new Controller with a public $template variable Your extended Controller will then inherit the $template variable from the Master Controller.
class MY_Controller extends CI_Controller
{
public $template=null;
public function __construct()
{
if(is_null($this->template)){
$this->template = 'layouts/default';
}
}
}
class Admin_Controller extends MY_Controller
{
public function __construct()
{
//Still inherits from MY_Controller
//this time, any controller extending Admin_Controller
//will point to 'views/layouts/admin'
if(is_null($this->template)){
$this->template = 'layouts/admin';
}
}
}
-
class User extends MY_Controller
{
public function index()
{
//$this->template is inherited
//from MY_Controller
//which point to 'views/layouts/default'
//We can also load a view as data
//ie no master layout, INTO our master layout
//note we don't pass $this->template
//and set the third param as true
$dynamic_sidebar = $this->load->view('views/sidebar/dynamic', array(
'data' => 'some_data'
), true);
return $this->load->view($this->template, array(
'partial' => 'users/index' //partial view,
'dynamic_sidebar' => $dynamic_sidebar
));
}
}
//load the main view
//in our example we have also loaded
//a dynamic sidebar with this view
load->view($partial); ?>
load->view($dynamic_sidebar); ?>
//load a static view
//views/sidebar/static
load->view('sidebar/static'); ?>