Creating custom templates for rendering common pages
Do not call 3 views in one controller function because they will limit you. instead call only one view which calls 3 other view.
this is your plan:
$this->load->view('header');$this->load->view($view,$data);$this->load->view('footer',$data);
the problem is that your header view will open some HTML tags which will be closed in footer view, such as div#container
. That will make your code illegible.
My suggestion is:
$main_data['a']=...$main_data['b']=...$main_data['c']=...$this->general_view('myview',$main_data);protected function general_view($main_view,$main_data){ $data['main_data']=$main_data; $data['main_view']=$main_view; $this->load->view('general_view',$data);}
inside general view:
<HTML> <HEAD> .... </HEAD> <BODY> <?$this->load->view('header');?> <div id="container"> <?$this->load->view($main_view,$main_data);?> </div> <?$this->load->view('footer',$data);?> </BODY><HTML>
Yes you can, just add a file inside views named masterpage.php, then use the following code:
<html><head></head><body><div class='menu'>My Menu here</div><div class='content'><?php echo $content; ?></div></body></html>
then your views shoud be like
<?php ob_start();?>content<?php $content= ob_get_contents(); ob_end_clean(); include("application/views/masterpage.php");?>
I hope it helps.