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

[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?
#2

[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.
#3

[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.
#4

[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!




Theme © iAndrew 2016 - Forum software by © MyBB