tags:

views:

106

answers:

2

I'm brand new to the MVC coding style and i'm having trouble deciding if i placed my code in the right place. I have a list of rates for an item, the rates have various time frames. what i want to do is display the highest rate per item for the current day. so say if item 1 has 3 rates, and 2 of them overlap today, it will choose the highest of those 2 rates and display it.

I placed this in the view since it applies to the way i am displaying the data. this is in cakephp so it's a web platform if that changes the way you think the controller/view should be applied.

+1  A: 

I typically put all of my logic in the controller and model so that my view only has markup and output statements. This will keep your views much cleaner and, especially if you are in a place where non-programmers might be editing views (e.g.: front-end implementors or content people), you run less of a risk of them messing things up.

Generally, I prefer thin controllers compared to models, and even thinner views (thin relating to the amount of logic in each division).

Justin Johnson
yeah that makes sense, thank you for your input. I'm moving it to the controller now.
Adrian Guido
Good luck! The controller is often the most mis-understood component of MVC. A lot of the time people try to do too much in the controller and make a mess of things.
Mike B
I'd go ahead and move this to the model, as I prefer fat models. You could do a Model::getRate( $itemNum, $time ) and pass the current time to $time if you define it right. Let the controller make that call and send the answer to the view, but I wouldn't have all this logic controller-side.
Travis Leleu
A: 

i separate reusable view code into elements. and put elements in its respective controller folder inside elements folder. so a page controller would have a element folder call /app/views/elements/page

Funky Dude