Welcome Guest, Not a member yet? Register   Sign In
Confused about libraries vs models
#5

[eluser]Buso[/eluser]
[quote author="mddd" date="1275565781"]In the end it is up to you, but I think the general idea is this:

- Controllers manage the flow of what has to be done and what has to be shown.
- Models take care of the 'thinking'. This is the core of what makes your application. This can be much more than just database work. If your application is meant for calculating things, you should do that in your models. So not only crud should be in a model; the main 'thinking' of the application should be in there.
- Libraries are supportive to your application. The provide specific intellegence to do certain tasks. Look at the CI libraries. There is one that knows how to deal with ftp, one that know how to resize images, etc.

It can help to think of an analogy, comparing your application to a company.
- Controllers are like the management. The main course is decided here. The management tells the rest of the company what to do, what to send where, etc.
- Models are the factory. The real work is done here. If the controller says 'make 50 things' it is done here. If stuff has to be looked up from the warehouse, it also done here.
- Libraries are like specific departments. They assist the main workflow that goes on in the factory and can do some specialized processing. Like the painting department in a car factory. The car is built in the factory, when it needs to a be painted it is taken from the line into the specialized paint shop and then goes back.

I know this doesn't work all the way, but it does help, I think.
To answer your specific question: no, libraries shouldn't be looked at as 'subcontrollers'. Look at them as building blocks that do specific things. In many cases they can even be re-used in another project. For instance if you have a library that looks up a location in Google maps -- this is a task that you might use again in another project. By taking it out of the models, you make it easier to use that specific function again![/quote]

Sounds like models should me more application-specific, and libraries more generic, am I right?

But what happens with things like say, an auth system? It should be reusable, it must access the database, and probably it needs to handle sessions too.

I could do all that in a model, in a library, or a combination of both. What would you recommend. It would be reusable in every case, I can throw the auth_model in and that would be it.


Messages In This Thread
Confused about libraries vs models - by El Forum - 06-02-2010, 10:43 PM
Confused about libraries vs models - by El Forum - 06-02-2010, 11:24 PM
Confused about libraries vs models - by El Forum - 06-03-2010, 12:45 AM
Confused about libraries vs models - by El Forum - 06-03-2010, 12:49 AM
Confused about libraries vs models - by El Forum - 06-03-2010, 12:57 AM
Confused about libraries vs models - by El Forum - 06-03-2010, 01:02 AM
Confused about libraries vs models - by El Forum - 06-03-2010, 01:06 AM
Confused about libraries vs models - by El Forum - 06-03-2010, 01:09 AM
Confused about libraries vs models - by El Forum - 06-03-2010, 01:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB