Jump to content

how do you decide what needs to be an object?


dadamssg

Recommended Posts

so i've been developing in the CodeIgniter framework and i have yet to code an object. My app deals with bookings. So in the database i have columns like: start, end, created, created_by, title, description, etc. I pull the data out and put it into an array. I use my controller functions to validate data and model functions to delete/edit/create the bookings. Should i write a class that creates a Booking object? i don't see how that would benefit me though.

 

How do you guys determine what needs to be an object?

From what I understand, the differences aren't vast.  There are some links I've clicked through while researching this myself and found some results that show associated arrays are a bit faster ( http://stackoverflow.com/questions/8498114/should-i-use-an-associative-array-or-an-object ). 

 

The difference in building them is miniscule anyway.  In CI your models are class extensions, so they are inherently prepared for object building and the active record is set up for object construction unless you request it in array format.

 

$this->result() versus $this->result_array()

 

The way I go about it is to create everything as an object and reference it to $this->data to pass to the view.

I always use arrays when using data from a database. A lot of the array functions don't work on objects, so if you want to use them you'll have to at some point convert the object to an array - which is just a waste of time when you could have used arrays to start with.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.