Codeigniter multiple views in one view

南楼画角 提交于 2019-12-21 13:26:11

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/17401686/codeigniter-multiple-views-in-one-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!