CodeIgniter Forums
Model or Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Model or Library (/thread-18916.html)



Model or Library - El Forum - 05-22-2009

[eluser]Hyra[/eluser]
This has been asked a hundred times over, but when looking at the various threads I can't find an "answer" to my specific issue. Maybe it's the fact it's morning and the coffee hasn't kicked in yet. But you loving cuddly igniters may have a solution.

Thing is, i'm reworking my site (artinvolved.com) which is 100% CodeIgniter ignited.

Now, as you can see it's all about images and users. I'm just having a big problem with the question: "Should i use libraries or models for the various tasks?"

For instance, the Browse model i have right now. It works fine, the controller creates an instance of the browser, gives it some parameters for "search", "size of thumbs" and so on. The model then retrieves all the thumbs + information about its creator back to me, which can be used. Same when viewing a single artwork.

But, wouldn't this just as well go into a library?

It would work exactly the same, as it's just a "dumb" little thing that retrieves data (i smell model) and finds the appropiate additional content (i smell library) that goes with it.

Any thoughts?


Model or Library - El Forum - 05-22-2009

[eluser]Phil Sturgeon[/eluser]
Models and libraries are both just Classes. You can use either for either, so it comes down to whatever you feel right doing.

The basic generalisations that I follow are:

Data handling = model.

Group of functions that share properties = library

Models can be used to get data from anywhere, getting meta data from an image is the same as a database or XML file. However if you do any processing on the images, resizing, etc then that would go in a library.


Model or Library - El Forum - 05-22-2009

[eluser]Colin Williams[/eluser]
Models manage, manipulate, and in some form represent your application resources.

Libraries facilitate/standardize common application procedures.

Look at core CI libs and make the verdict: Is the class managing resources, or facilitating procedures. The former can be argued for some but it is typically a stretch.


Model or Library - El Forum - 05-22-2009

[eluser]Hyra[/eluser]
Kind of seems the 'correct' approach is to split them up.

If i keep on the example of Browse functionality then i could split it up in a Model for the "getting the image locations from the database depending on the criteria" and a Library for resizing them down on the fly and such.

This is of course not the only way. In fact, it might not be very practical in terms to maintain the code.

I guess ill just stick with how i have it working now (models)

Thanks!