Php 在非CI类上访问CI功能
例如,我想从类库访问CI的配置Php 在非CI类上访问CI功能,php,codeigniter,Php,Codeigniter,例如,我想从类库访问CI的配置 Class A { funcion x() { $this->config->load('my_config'); // accessing my_config } } 除非扩展并调用parent::\uu construct(),否则这显然是行不通的 据我所知,它只能从扩展CI_控制器或CI_模型的类中完成。如何在非CI类上访问CI内容(配置、帮助器、模型等) 谢谢。从构造启动类怎么样 include ("CI_Page.php"
Class A {
funcion x() {
$this->config->load('my_config'); // accessing my_config
}
}
除非扩展并调用parent::\uu construct(),否则这显然是行不通的
据我所知,它只能从扩展CI_控制器或CI_模型的类中完成。如何在非CI类上访问CI内容(配置、帮助器、模型等)
谢谢。从构造启动类怎么样
include ("CI_Page.php");
class A {
protected $_CIInstance1;
protected $_CIInstance2;
public function __construct(){
$this->_CIInstance1 = new xxxx();
$this->_CIInstance2 = new yyyy();
}
public function x(){
$this->_CIInstance1->load('my_config');
}
}
您可能希望访问
CI
的实例,就像它是超级变量一样,$this
。实际上,您需要的是能够访问与$this
相同的功能,为此,您需要使用$CI=&get_instance()代码>
您可以直接在