Welcome Guest, Not a member yet? Register   Sign In
Quick MVC / Library question
#1

[eluser]bapobap[/eluser]
Hi there,

I'm currently re-building an application bit by bit and am trying to do everything the right way. I have a quick question if anyone can help. I think an example will help.

A user uploads a photo
I take the photo, convert it and resize it, move it to where it needs to be stored
I add a row to the database

I'm fine with controllers and views but I'm still slightly confused as to what should be the correct way to handle this with Models/Libraries. At the moment I have a Photo library, which has all the necessary methods needed to handle converting the image, resizing it, putting it in the right place etc. The photo model then has a few methods to add/delete database records which the photo library then calls.

Should I maybe have all of this functionality in the model, or maybe all just in the library or am I doing things wrong? It just gets a bit confusing having a set of photo views, a photo controller, a photo library then a photo model, all to handle what is essentially, add/edit/delete.

Any advice is appreciated!
#2

[eluser]Colin Williams[/eluser]
Sounds like you are on the right track. Sounds like you have separation anxiety, as in you fear separating what you mentally see as one process into multiple areas. Mental modeling and application modeling are different.

Also, you might consider letting your model do most of the heavy lifting, not by containing the code the library does, but by using the library. For instance, you might have a model method that is save_photo() to which you pass an array of sizes to make

Code:
$this->photo->save_photo(array('thumbnail', 'preview'));

Your controller runs that one line. The logic in the line is "save these kind of photos." That's the kind of traffic-cop-like logic you want your controller doing. Your model then uses the library to do the resizing, database queries, etc.




Theme © iAndrew 2016 - Forum software by © MyBB