Welcome Guest, Not a member yet? Register   Sign In
Populating an array of objects using CI's load->model() functionality
#1

[eluser]paulkmoore[/eluser]
Hi all - newbie post, so please feel free to redirect me if appropriate

I am trying to create an array of objects each of which is an instantiation of a Model. For context, I am modelling financial transactions in a hierarchy with a typical header and details relationship.

I have a Model for the tx header, and a model for tx detail, where one tx header has many tx detail subordinates.

I'd like to create the tx header and create an array of tx detail objects to represent the 'full' transaction.

I can instantiate single instances of both models within the controller fine, but I'm struggling to load multiple tx detail objects.

If I've understood the CI internals correctly all Models loaded using the load->model construct are mapped to the CI superobject (which is a Singleton), and therefore each object will be unique by name. This is set out in Loader.php which allows for the object to be reference by a specified name (as per the excellent CI user guide) - however, the name is required to be a string and therefore I am unable to call the load->model with an array element for a name.

i.e. $this->load->model('my_tx_detail_model', "txd[3]"); (reasonably) fails.

Is this a limitation of the CI superobject (singleton) design choice (flowed through to Loader.php), or is there some other approach I could be using to instantiate multiple Model objects? I've seen some reference to splobjectstorage, but again not sure whether this reasonably fits with the CI singleton or not.

Many thanks in advance

Paul


Messages In This Thread
Populating an array of objects using CI's load->model() functionality - by El Forum - 04-21-2010, 02:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB