Welcome Guest, Not a member yet? Register   Sign In
Is a library appropriate?
#3

[eluser]Jelmer[/eluser]
There's different ways of implementing the MVC pattern using CI's implementation. My personal opinion is that it's pretty much up to you to choose which is better.

I use models when it's about CRUD operations on database data (or any other kind of data that benifits from having an object represent it). If I use CI with Active record I generally implement my models in a way that I load a new instance of the model for each row retrieved from the database. When I use RapidDataMapper (an ORM) I generally implement models to work as gatekeepers in retrieving RDM's objects.

Libraries (IMO) can be application specific, but should not do CRUD operations (unless it's wrapping them in a general way to be usefull for models). I view libraries as toolboxes that are either singleton (never more then 1 instance) or are instanced only to change how or where they operate, but not to represent data.

Sometimes it's difficult to make a choice. I recently created a file access library that wraps native PHP functions like rename(), unlink(), etc. I could have implemented it as a model because it's about data access. But in the end I made it very general and I've implemented it in 2 models that work with configurations of the library (one for general files and one for images).

But to get back to the OP's question: in your case a model seems to be indeed the best solution because it's about clients and I think you could best implement it in a way that each instance you load represents a single client. Or you could create both a library and a client model where the library handles some of the higher function operations and the model is purely about representing the client and doing CRUD operations.


Messages In This Thread
Is a library appropriate? - by El Forum - 08-29-2010, 12:09 PM
Is a library appropriate? - by El Forum - 08-29-2010, 07:31 PM
Is a library appropriate? - by El Forum - 08-30-2010, 04:34 AM
Is a library appropriate? - by El Forum - 08-31-2010, 10:40 PM
Is a library appropriate? - by El Forum - 09-01-2010, 12:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB