Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter: How can I create a new instance of a library whenever the method is called?
#1

[eluser]mrking[/eluser]
just some snippet of the code

Code:
function __construct() {
   $this->ci = &get;_instance();
   ...
   ...
}

function run() {
   foreach($run_2_time as $run){ $this->deduct_user_point(); ... ... }
}

function deduct_user_point() {  
   $this->ci->load->library('user_lib');
   ...
   ...
}

Firstly, i know that by executing $this->ci->load->library, it will create an object of the class but will subsequent call by the foreach loop in run() create a new object. My thought is no, but someone please verify.

And yes, I do know of one other alternative, which is to insert a third parameter into $this->ci->load->library which is unique for every loop,

Code:
$this->ci->load->library('user_lib','',$class_name);

and that might solve the problem, but is that the only solution?


Messages In This Thread
CodeIgniter: How can I create a new instance of a library whenever the method is called? - by El Forum - 10-07-2009, 02:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB