Welcome Guest, Not a member yet? Register   Sign In
Want class to encapsulate database records, where to put it?
#4

[eluser]davidMC1982[/eluser]
I think of it like this:

Any functionality that is specific to a data entity (database table, record etc) belongs in a model. All interaction with the database should happen through this model.

Any functionality that is generic (independent of a specific model) belongs in a library. This will include things like sending emails, authentication, generating pdf's from views etc etc.

Basically, if you find yourself repeating code in various controllers, it probably belongs in a model if it's entity specific or in a library of it's generic. And if it's just a simple function being repeated, stick it in a helper.

Regarding setting a prefix, this is useful to avoid database table name collisions between your tables, the tables required by libraries and - when on shared hosting - the tables of your other sites.


Messages In This Thread
Want class to encapsulate database records, where to put it? - by El Forum - 10-18-2013, 12:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB