关于$this->view。急急急,在线等……
刚接触CI。所以对里面的一些变量机制不是很了解。 想请问一下关于$this->view这个是什么样的一个数组。这是我看到的一段代码:$this->load->view('home/index', $this->view);
根据我的理解应该会把$this->view这个数组发送到home/index这个页面上。但是我对这个很不了解。请大神回复。在线等
key => value数组啊
你再了解以下extract函数就明白怎么一回事了 jeongee 发表于 2012-7-9 12:08 static/image/common/back.gif
key => value数组啊
你再了解以下extract函数就明白怎么一回事了
不是, 我是想问一下$this->view这个数组代表什么东西i。 是内置的还是用户自定义的? 应该是内置的吧! 拉风的牛仔 发表于 2012-7-9 12:14 static/image/common/back.gif
不是, 我是想问一下$this->view这个数组代表什么东西i。 是内置的还是用户自定义的? 应该是内置的吧! ...
自定义,这个是个性化的东西,怎么内置呢,系统无法知道你要传递什么东西给视图 LZ多看看手册吧,http://codeigniter.org.cn/user_guide/general/views.html手册中视图介绍里的“给视图添加动态数据”部分或许是你想要的 其实再写点你就明白了,看代码
$args = array();
$args['view'] = "这是一个测试数据";
$this->load->view('test',$args);
///////////////////////////////////
test 视图中你直接
echo $view;
就会输出这是一个测试数据
你说的$this->view 就相当于 $args 只是看你怎么写了
当然你也可以
$this->view=$args;
$this->load->view('test',$this->view); 本帖最后由 feizhoulv 于 2012-9-3 09:35 编辑
楼上的很正确,如果想传递一个页面可以附加第三个参数。
用法:
$data['content'] = $this->load->view('mycontent', array(), true);
$this->load->view('mypage', $data);
函数原型
// --------------------------------------------------------------------
/**
* Load View
*
* This function is used to load a "view" file.It has three parameters:
*
* 1. The name of the "view" file to be included.
* 2. An associative array of data to be extracted for use in the view.
* 3. TRUE/FALSE - whether to return the data or load it.In
* some cases it's advantageous to be able to return data so that
* a developer can process it in some way.
*
* @param string
* @param array
* @param bool
* @return void
*/
public function view($view, $vars = array(), $return = FALSE)
{
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
你print_r()或者var_dump()打印出来看看先,就是传递参数给页面的而已
页:
[1]