I’m really struggling recently with understanding some basics of MVC. I’m sold on the concept, but confused when it comes to asking hard questions like which kind of data manipulation goes into which box: model or controller. Hopefully someone can help me out, because searching isn’t yielding much. For background, I’m using PHP, CodeIgniter and PostgreSQL as my database. That really shouldn’t matter much, but it helps to know what the Model is accessing (using SQL).
The basic question I have is, if you are running a complex query where you would have specific instructions on how to order the data, who does the ordering? the Model or the Controller?
If it’s the Model … then how do you pass in the order by variables into a function? Do you have an argument that takes an ORDER BY variable that is inserted into your SQL statement? Do you write specific functions in the Model that spit out the data in the possible orders that are available from the View?
If it’s the Controller … then how the heck do you order it? Do you grab all the data, and then run ways to sort the arrays? That seems extremely tedious.
I could go on ranting more, but I think I’ll leave my question as small as that for now. Frankly, I’m stumped.
My situation I’m in right now is that I’m building reports which pull together data from multiple sources, and then need to organize them based on the most simplest ordering scheme which spans multiple columns. That is, order by this first, then that, then the third column. That’s all fine and good, but what about when the client wants to rearrange the data? That’s where I get lost.
Basically, my question is, if you are customizing data presented to the View, based on input from the client, where does the lifting go, and how do you get it in there? Like I said, I’m lost.