Welcome Guest, Not a member yet? Register   Sign In
Best practice - Library or Model?
#1

[eluser]Unknown[/eluser]
Hi all,

Just getting in to CodeIgniter and enjoying it so far. I'm new to everything.

Small question for the community.

I'm wondering what the best practice is though: Library or Model?

Is there a simple rule to follow for the purpose of ones library or model, in order to determine which is more appropriate?

I notice the example in the user guide for a model is a blog - what would be the main reason for using a model instead of a library class in this example?

Help appreciated all

Regards
#2

[eluser]xwero[/eluser]
It are the methods that more important than the name of the model in the model example.

All data manipulation an retrieval should be handled by a model. Libraries are there for display manipulation of the retrieved data. I think that is the most basic rule but there are a lot of gray areas where you have a mix of model and library or library and model.
#3

[eluser]Unknown[/eluser]
Thanks for your reply xwero, much appreciated.

Could I also ask - is it the done thing to call models within libraries?
Or should I try to call models within controllers only?
#4

[eluser]xwero[/eluser]
I try to stick by the basic rule and call models in libraries but you have to be aware if you use models in libraries the library is bound to CI. Where if you use native php database functions your library will be usable in different frameworks. It's a question of where you draw the reusability line.
#5

[eluser]zpjorge[/eluser]
Really depends on what you are doing and what sort of app you are building.

I tend to use models for large, dynamic applications. Models for building functionality into smaller aspects of the site.




Theme © iAndrew 2016 - Forum software by © MyBB