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

[eluser]ipavlic[/eluser]
Hello everyone.

I am new to CodeIgniter and rather new to php. I have been coding in CI for the last month. I have found the community responses to other people's questions very helpful in resolving various problems I have had along the way.

I am hoping to receive some advice from you on the following problem:

To solve a resource management task, I implemented an algorithm in a .php file (i found it quicker to draft and test the code in basic php and after testing "transfer" the code to CodeIgniter).

The Algorithm class instantiates various classes to store objects needed to solve the resource management problem, and then proceeds to calculate the solution.

I found how to instantiate and use the needed objects in threads Best Practice for instantiating classes in Libraries that are non-singletons? and Best practices using multiple object instances?.

I decided to use load_class
Code:
class Algorithm extends Controller
{
    // variables -- will hold class instances after construction
    function Algorithm()
    {
        parent::Controller();
        load_class('myclasses',false);
        // instantiate other needed classes and assign them to variables
    }
    // functions to calculate the solution
}
in the constructor of the 'Algorithm' controller. The file myclasses contains necessary class definitions.

In order for the classes to instantiate, they need to pull some information from the database, so I would write an algorithm_model.php.
After instantiating, the Algorithm class contains other classes which in turn contain some other classes.

My questions are:
- Would it be more in the spirit of CI to just put the Algorithm class in myclasses, along with the other ones?

Also, I don't quite understand the CI superobject:
- If two users make two requests to various controllers, are then two superobjects created (each including the Controller class instantiated with different parameters)?
- Is then the CI superobject a singleton "per call" (marked for destruction after processing the function call requested via url)?
- And is then the CI "running" for only as long as it needs to complete a single function call of some user?
- Whether I put the Algorithm in myclasses and instantiate it or make it a controller class which gets instantiated by requesting the appropriate url, both the Algorithm class and the class instances it contains as variables are contained in the CI superobject, are they not?

I realize these are probably elementary questions :red:, but am confused with explanations like this one (emphasis mine):
Quote:CI works by building one 'super-object': it runs your whole program as one big object
.
I am grateful for any pointers and clarifications.


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