Possible Duplicate:
get_instance() in Codeigniter: Why assign it to a variable?
I have a controller, and it have lots of functions, I would like to separate them into different cmd object. But in controller, I can do the $this magic, for example, I can call something like this:
$this->form_validation->run('myAction');
But when I move this code to an object, which is not a controller, so, I called the function like this:
$CI =& get_instance();
$CI->form_validation->run('myAction');
I realize that they can run, and the result is exactly what I want. But, my question is, is these two operation or codes have any different? What is the get_instance() black magic inside? Did the controller’s $this refer to the same get_instance()? Thanks.
using the
$ci = &get_instance(), you’re directly using the codeigniter native libraries, you’re not making a copy of it. The “$this” command can be used only in inside the controllers, so assign the CI object to a variable is the only way you’ve got to go inside the Ci core libraries outside the controller. Note that the “$this” command inside a model refer to the model object itself.