用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1536|回复: 4
收起左侧

[已解决] $CI =&get_instance()出错

[复制链接]
发表于 2015-3-31 14:40:11 | 显示全部楼层 |阅读模式
本帖最后由 ywmprogrammer 于 2015-4-1 15:16 编辑

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

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

求大神啊,什么原因

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

发表于 2015-3-31 16:52:41 | 显示全部楼层
没有继承CI类
发表于 2015-3-31 17:07:59 | 显示全部楼层
PHP复制代码
 
 
class test extends CI_Controller {
    public function bac()
  {
  $ci = & get_instance();
  $ci->load->helper('other');
  }
}
 
 
复制代码



类继承:类名 extends CI_Controller
发表于 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()自己,源代码:

PHP复制代码
function &get_instance()
    {
        return CI_Controller::get_instance();
    }
复制代码


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

发表于 2015-3-31 17:42:18 | 显示全部楼层
报什么错都不说。。

本版积分规则