我读过this question,但它帮不了我太多。
在使用Ion_auth
库时,我注意到视图的数据是由$this->data[]
传递的,而不是由$data
简单传递的。
为什么?这样做的区别或优势在哪里?
发布于 2018-02-22 17:47:24
使用$this->数据意味着您可以利用父控制器的OOP继承。父控制器,如MY_controller,可以设置一些初始数据,这些数据在扩展它的所有控制器中都可用。
这里有一个例子:http://avenir.ro/codeigniter-tutorials/creating-working-with-my_controller-codeigniter/
发布于 2015-10-04 12:04:01
这意味着你必须在你的类中定义$data
成员,
和$this
引用当前对象,也就是当前类
当您定义
Class Oop
{
private $data = array();
function test()
{
$this->data['title'] = 'Home';
echo $this->data['title']; //access like this
}
}
在codeigniter中,$data
是一个数组
在控制器中,你可以$data['title'] = 'Home';
,然后在视图中,你可以像$title;
一样访问它
请参考this oop
https://stackoverflow.com/questions/32929758
复制相似问题