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

[eluser]ipavlic[/eluser]
[quote author="WanWizard" date="1281183277"]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).[/quote]

I decided to make a library out of the 'Algorithm' class, and load the required objects using require_once.
The arrays of instances of various classes are used to store information, so I do need multiple instances of them.

The final structure looks like this:
Code:
/*
/classes
..
class1.php
class2.php...

/libraries
..
algorithm.php
*/

class Algorithm
{
    protected $CI;
    private class1_instances = array();
    private class2_instances = array();
    //other variables
    public function Algoritm($input = array())
    {
        $this->CI =& get_instance();
        require_once(APPPATH.'classes/class1.php');
        require_once(APPPATH.'classes/class2.php'); //...

        $this->initialize_class1_instances();
        $this->initialize_class2_instances(); //...
    }
    // private function initialize_class1_instances()...

[quote author="WanWizard" date="1281183277"]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.[/quote]

Yes, that makes much more sense than the quote i put in my first post.

Thank you very much for your feedback.


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