Php 在自定义类的contstructor中初始化Codeigniter实用程序
我做CI已经有几个月了,我想在CI上创建自己的库类。现在,我的问题是,我似乎无法获得CI的实例,以便利用其本机资源。我已经做到了Php 在自定义类的contstructor中初始化Codeigniter实用程序,php,codeigniter,Php,Codeigniter,我做CI已经有几个月了,我想在CI上创建自己的库类。现在,我的问题是,我似乎无法获得CI的实例,以便利用其本机资源。我已经做到了 class MyClass{ protected $instance; public function __construct() { $this->$instance = &get_instance(); <-- this is what i did (theoretically speaking)
class MyClass{
protected $instance;
public function __construct()
{
$this->$instance = &get_instance(); <-- this is what i did (theoretically speaking)
}
}
class-MyClass{
受保护的$实例;
公共函数构造()
{
$this->$instance=&get_instance();protected$instance=&get_instance()
PHP不支持PHP
那么你是怎么做到的呢?嗯,它解决了问题..但是还有其他想法吗?我觉得$this->ci->load有点长..或者我只是太懒了,呵呵,但无论如何我对任何想法都是开放的..@lemoncodes我的意思是你可以使用这个代码,但是可以替换$this->ci(这不好读)使用$CIyo man,当您想在构造函数上使用$ci时,将$this->ci替换为$ci是可以的。但是当您在其他函数中使用$ci时,它无法看到$ci超出其作用域
class MyClass{
protected $instance = &get_instance(); <-- reports a syntax error on Apatana
public function __construct()
{
}
}
you can use it in this way
in constructor
$this->ci = & get_instance();
then you can use it like
$this->ci->load->model();