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

[eluser]paulkmoore[/eluser]
Dan et al

Thanks for all the feedback - I really appreciate it. Here's what I have concluded:

The reason I was getting into a mess with i) multiple instances of Models and ii) hierarchies of Models is that I was trying to implement object aggregation of the Transaction header and details exclusively within the MVC framework. Understanding (thanks Dan) that I could and should maintain these objects elsewhere and utilise them in the MVC framework was the leap I had missed (looks simple in retrospect!).

So here's what I have ended up with in pseuso code:

Code:
class Transaction_object
{
//Common properties

public $details = array();  // holder for the tx details objects

}

class Transaction_type_1_object extends Transaction_object
{
//Properties specific to this type of transaction

//Method overload where required from the base class
}

class Transaction_type_2_object extends Transaction_object {}

class Transaction_type_3_object extends Transaction_object {} // etc etc

class Transaction_detail_object
{
//Common properties
}

class Transaction_detail_type_1_object extends Transaction_detail_object {}

class Transaction_detail_type_2_object extends Transaction_detail_object {}  // etc etc

This allows flexible arrangements of the transaction header and details without coupling too tightly, and the extended classes allow good precision in terms of the object properties and methods i.e. I can really lock these down.

I chose not to implement as CI libraries in the end as the loader.php calls the constructor on load, which wasn't appropriate in all cases. Usage of a require_once where I want to use the objects works well however.

Thanks again to all for the help

Best regards

Paul


Messages In This Thread
Populating an array of objects using CI's load->model() functionality - by El Forum - 04-27-2010, 04:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB