Several views of Codeigniter in one view

I am working on a web application. It may be a stupid question, but I want to know if I take a good approach to this or not. I want to have multiple views on one separate view / page.

The Codeigniter documentation says, "A view is just a web page or a fragment of a page, such as a header, footer, sidebar, ...".

I want to have a headline, some quick search, a different view and footer for an example. Should I implement a controller for each view (title, quick search, footer ...) or is it better to implement all the viewing functions in one controller? For example, if I know that the header, footer, quick search views will always be there (even if their contents may change), should I put functions for all these views in one controller?

Please, help.

+6
source share
1 answer

one approach is to have the form of a template that has the required elements. see this pseudocode example ... therefore, 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 a template with parameters for each view.

 $data = new stdClass(); $data->header = .... $data->quickssearch = .... $data->body = ..... $data->footer = ..... $this->load->view('template_view',$data); 
+5
source

Source: https://habr.com/ru/post/948460/


All Articles