在一个视图中Codeigniter多个视图 [英] Codeigniter multiple views in one view

查看:168
本文介绍了在一个视图中Codeigniter多个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序。这可能是一个愚蠢的问题,但我想知道我是否采取良好的方法,这或不。
我想在一个视图/页面上有多个视图。

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.

Codeigniter文档说

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?

请帮助。

推荐答案

一种方法是拥有包含所需元素的模板视图。
看到这个伪代码示例...
so,template_view.php has:

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

这篇关于在一个视图中Codeigniter多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆