Welcome Guest, Not a member yet? Register   Sign In
How to use models?
#11

[eluser]Buso[/eluser]
[quote author="zoran119" date="1283870019"]hi all,

i was hoping someone can tell me what is the correct way to use models.

i have a model called 'application' extending the ci model class, but i just have a bunch of functions there which get used in the controller called 'application'. this model does not have any private variables. for example, there is a function update_status($application_id, $new_status_id) which i call from the controller like this

Code:
$this->load->model('application');
$this->application->update_status($application_id_to_update, $new_status_id);

i'm thinking that this is not the way to do things. should the model be used as a proper class, with properties and methods? so for the example above, should the application model have a private property called status_id and then implement a method called set_status_id($new_status_id) to set the private property and another method called save() which would save the change to the database?

i'm thinking it should be done the second way, just not sure. anyone got an opinion?[/quote]
Both approaches are commonly used.

Personally, I prefer the first one (but suffix your models with '_m' or '_model' so you don't have collisions with say, libraries), but if you like the second one you can try DMZ out. It's an ORM for Codeigniter.

Oh and remember that models are supposed to handle your business logic in general, not only database-related stuff.


Messages In This Thread
How to use models? - by El Forum - 09-07-2010, 03:33 AM
How to use models? - by El Forum - 09-07-2010, 07:17 AM
How to use models? - by El Forum - 09-07-2010, 07:51 AM
How to use models? - by El Forum - 09-07-2010, 07:52 AM
How to use models? - by El Forum - 09-07-2010, 07:59 AM
How to use models? - by El Forum - 09-07-2010, 10:34 AM
How to use models? - by El Forum - 09-07-2010, 05:15 PM
How to use models? - by El Forum - 09-07-2010, 05:16 PM
How to use models? - by El Forum - 09-07-2010, 10:55 PM
How to use models? - by El Forum - 09-08-2010, 02:46 AM
How to use models? - by El Forum - 09-08-2010, 02:55 AM
How to use models? - by El Forum - 09-08-2010, 07:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB