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 如何在CodeIgniter中自动实例化库_Php_Codeigniter - Fatal编程技术网

Php 如何在CodeIgniter中自动实例化库

Php 如何在CodeIgniter中自动实例化库,php,codeigniter,Php,Codeigniter,我在Codeigniter中使用了一个非常基本的库。为了使用它,我需要使用config函数传入一些配置参数。我的库当前要求我先实例化它,然后才能调用配置,即我必须按如下方式使用它: $this->load->library('Library'); $instance = new Library(); $instance->config($configparams); class Library { function config($configparams){

我在Codeigniter中使用了一个非常基本的库。为了使用它,我需要使用config函数传入一些配置参数。我的库当前要求我先实例化它,然后才能调用配置,即我必须按如下方式使用它:

$this->load->library('Library');
$instance = new Library();
$instance->config($configparams);
class Library {

     function config($configparams){
       ...
     }
}
我想像使用标准CodeIgniter库一样使用它:

$this->load->library('Library');
$this->library->config($configparams);
为了让库自动实例化,我需要向库中添加什么?代码如下:

$this->load->library('Library');
$instance = new Library();
$instance->config($configparams);
class Library {

     function config($configparams){
       ...
     }
}
这正在工作。我发誓在我发布之前它不起作用!谢谢你的帖子。

根据,你应该打电话给它。因此:

$this->load->library('Library');
$this->library->config($configparams);
但是为什么不直接将
$configparams
传递给构造函数:

$this->load->library('Library', $configparams);

查看CodeIgniter指南——这是了解更多关于框架的好资源。嗯,目前的版本没有什么好书;就是这样

你基本上把它叫做其他任何东西

$this->load->library('Name of Library')
在此处阅读更多信息:

一旦加载类

$this->load->library('someclass');
那么在使用的时候,需要使用小写,比如:

$this->someclass->some_function();
对象实例总是小写的