什么是部分视图? [英] What are Partial Views?

查看:161
本文介绍了什么是部分视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Codeigniter,以习惯于模型 - 视图 - 控制器架构,并尝试和加快制作和实施网站的过程。

I've been using Codeigniter in order to get accustomed to the Model-View-Controller architecture, and to try and speed up the process of making and implementing sites.

我看到对部分视图的引用,但是找不到该术语的定义。

I keep seeing references to "Partial Views" but can't find a definition for the term.

任何人都可以告诉我什么是部分视图,并在哪里使用?

推荐答案

部分视图只是一个子视图,父视图。让我们来看一个常见的例子:

A partial view is just a sub-view that you can include in a parent view. Let's take a look at a common example:

// Controller:
$data['myvar'] = array('element1', 'element2', 'element3');
$this->load->view('myview', $data);

// Myview:
<ul>
  foreach ($myvar as $var) {
    $this->load->view('partialview', array('var', $var));
  }
</ul>

// Partialview:
<li><?= $var ?></li>

这对根据列表重复内容很有用。
请注意,视图和partialview之间没有什么不同,它只是你定义该术语的方式。

This is useful to repeat content according to a list. Note that nothing differs between a view and a partialview, it's just the way you include it that defines the term.

这篇关于什么是部分视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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