Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在非CI类上访问CI功能_Php_Codeigniter - Fatal编程技术网

Php 在非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"

例如,我想从类库访问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 {
     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()

您可以直接在