Welcome Guest, Not a member yet? Register   Sign In
Object instances and CI superobject

It's probably easier to turn your other classes in libraries or models, and use them the standard way instead of using load_class() and manual instantiation. load_class() is an internal function that has changed in CI2, it now always instantiates the object (the second parameter is no longer present).
if you need multiple objects you have to manually load them using require_once(APPPATH.'classes/myclass.php') (assuming your classes are in a separate classes directory).

As to you other questions: HTTP is stateless, so every request made to the webserver will load your index.php (and everything after it) as a separate process. So yes, a CI superobject exists per call. When CI has finished processing the request, the script ends and the object and all data are gone. This is not CI specific, this is the way web applications, and PHP is particular, work.

Everything instantiated by CI is part of the CI super object, so it is accessable everywhere using $this. If you instantiate your classes manually, you have to assign them to the CI superobject manually if you want that same behaviour.
// this is a local object
$my_object = new My_object();
// this is a CI object
$CI =& get_instance();
$CI->my_object = new My_object();

Messages In This Thread
Object instances and CI superobject - by El Forum - 08-06-2010, 05:36 PM
Object instances and CI superobject - by El Forum - 08-07-2010, 01:14 AM
Object instances and CI superobject - by El Forum - 08-07-2010, 02:07 PM

Theme © iAndrew 2016 - Forum software by © MyBB