dongyirong3564 2011-02-11 01:59
浏览 17

如何在CodeIgniter中自动实例化库

I'm using a really basic library in Codeigniter. In order to use it I need to pass in a number of config parameters using a config function. My library currently requires me to instantiate it before I can call the config, i.e., I have to use it as below:

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

I'd like to use it like standard CodeIgniter libraries:

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

What do I need to add to the library in order to have it auto-instantiate? The code is as below:

class Library {

     function config($configparams){
       ...
     }
}

This is working now. I swear it wasn't working before I posted on SO! Thanks for posts.

  • 写回答

3条回答 默认 最新

  • dsk95913 2011-02-11 03:40
    关注

    According to the docs, you should just call it. So:

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

    But why not just pass $configparams to the constructor:

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

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因