Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter multiple views in one view

I am working on a web application. This might be a silly question, but I want to know whether I am taking the good approach to this or not. I want to have multiple views on one single view/page.

The Codeigniter documentation says that "A view is simply a web page, or a page fragment, like a header, footer, sidebar, ...".

I want to have a header, some quick search view, some other view and a footer for a example. Should I implement a controller to every view (header, quick search, footer, ...), or is it better to implement every view functions in a single controller? For instance, if I know that the header, footer, quick search views are going to always be there (even if their content might change) should I put functions for all those views in one controller?

Please, help.

like image 724
kalafun Avatar asked Jul 01 '13 09:07

kalafun


1 Answers

one approach is to have a template view that has the elements you require. see this pseudo-code example... so, template_view.php has:

$this->load->view('header',$header);    
$this->load->view('quicksearch',$quickssearch);    
$this->load->view('body',$body);    
$this->load->view('footer',$footer);

your single controller then calls the template with the parameters for each view.

$data = new stdClass();
$data->header = ....
$data->quickssearch = ....
$data->body = .....
$data->footer = .....

$this->load->view('template_view',$data);
like image 80
pgee70 Avatar answered Oct 04 '22 19:10

pgee70