ywmprogrammer 发表于 2015-3-31 14:40:11

$CI =&get_instance()出错

本帖最后由 ywmprogrammer 于 2015-4-1 15:16 编辑

在自定义类库中使用CI资源报错


class test {
    public function bac()
{
$ci = & get_instance();
$ci->load->helper('other');
}
}

求大神啊,什么原因

补充:后面认真看代码发现是我写错了

因為愛 发表于 2015-3-31 16:52:41

没有继承CI类

mlym3075 发表于 2015-3-31 17:07:59



class test extends CI_Controller {
    public function bac()
{
$ci = & get_instance();
$ci->load->helper('other');
}
}




类继承:类名 extends CI_Controller

yuzhigang5460 发表于 2015-3-31 17:28:39

mlym3075 发表于 2015-3-31 17:07
类继承:类名 extends CI_Controller

肯定是其他地方出错。
在CI的Controller里,不需要这么写, 用$this 就可以了:
$this->load->helper('helper');

$this就是 &get_instance()自己,源代码:

function &get_instance()
    {
      return CI_Controller::get_instance();
    }

你的错误应该在其他地方。

合合 发表于 2015-3-31 17:42:18

报什么错都不说。。
页: [1]
查看完整版本: $CI =&get_instance()出错