Tom*_*ick 10
codeigniter超级对象是一个对象,它允许您引用任何已加载的codeigniter资源或加载新的资源,而无需每次都初始化类.
例如,在您的库中,如果您想要引用数据库,则可以执行以下操作
function whatever()
{
$this->ci =& get_instance() // sets an object in your library to point to the codeigniter object
$this->ci->db->get('mytable');
}
Run Code Online (Sandbox Code Playgroud)
它在控制器中的位置
function whatever
{
$this->db->get('mytable);
}
Run Code Online (Sandbox Code Playgroud)
这是因为默认情况下库没有对codeigniter对象的引用(出于多种原因)