Welcome Guest, Not a member yet? Register   Sign In
Create Master view file
#1

[eluser]Techno Heart[/eluser]
Hi all,

I am doing a project in code igniter. I am using the header.php file in my project which is loaded in every controller in the project.
What i want is instead of loading it every time in all controller,load it only once throughout the project which is applicable for all the pages.? Any one there to help me ? Is it possible.?
#2

[eluser]RedIgniter[/eluser]
That's what I do to, load it everytime from the controller.
#3

[eluser]pickupman[/eluser]
Check out base controllers in my signature. Using this idea you can call the header in the construct of your base controller. Remember that calling a view only queues it to be displayed. Final output is handled by codeigniter.
#4

[eluser]techgnome[/eluser]
what I did was to create a template folder in my view folder, and put my mast view there. Each of my controllers then load that one view. Part of the data that is passed to the template view is the specific view for the content area. So my template.php file then loads the header, the main navigation, the content (based on the $contentview variable, determines if the right side bar gets loaded as well (also controlled via a value passed form the controller) and the footer. 75% of my pages are all the same, and if I have to add something to the navigation, I only need to do it in one file (views/template/leftcol.php)

-tg
#5

[eluser]CroNiX[/eluser]
I just create a library with a render_page() function.

Something like
Code:
//data is the data array which is passed to my "active" view, the one named in $view_file;
render_page($view_file, $data)
{
    $this->load->view('header', array());
    $this->load->view($view_file, $data);
    $this->load->view('footer', array());
}
This is the most basic, because I am also loading other widgets, like login status, automatically here so I don't have to do it from my controllers.

then in my controllers...I just
Code:
//...do my stuff...
$data['something'] = $this->get_some_data();
$data['something_else'] = $this->some_model->get_even_more_data();

//...
//then
//...

$this->common_controller->render_page('admin/some_view_file', $data);
and everything else is done automatically. It leaves your controllers a lot cleaner because you aren't polluting them with "outside" code. Its only dealing with the specific thing it was designed to deal with.




Theme © iAndrew 2016 - Forum software by © MyBB