Page 1 of 1

MVC 'best practice' for displaying data

Posted: Wed Dec 01, 2010 2:51 pm
by Celauran
So this is a pretty trivial question and it's possible I'm just overthinking things, but here goes:

I've got a form for users to get rates calling from City A to City B. The controller validates the $_POST information, sends it off to the model to fetch the required data from the database, gets the results from the model and then sends them back to the view to be displayed. So far, that's my understanding of how things are 'meant' to work. Now, when displaying the results, I want to display either Calling from Country; Calling from City, Country; or Calling from City, State as the case warrants. City, State, and Country are all columns in the database, so the model returns them all in the result array. My question, then, is whether the logic to determine which combination of columns to display belongs in the controller or the view.

On the one hand, I think it's purely a question of display and belongs in the view. On the other, I think it's maybe better for the view to expect one value to display and for the controller to decide what it contains. I realize, of course, that either will get the job done but, as I'm still relatively new to the whole MVC approach, I figured I'd ask if there was an accepted 'correct' way of doing this.

Thanks for your help.

Re: MVC 'best practice' for displaying data

Posted: Wed Dec 01, 2010 3:00 pm
by Celauran
And, of course, only now do I see this thread dealing with pretty much the same thing. Sorry.

Re: MVC 'best practice' for displaying data

Posted: Wed Dec 01, 2010 3:01 pm
by s992
Well, damn. I was about two seconds away from linking that thread! :D

Re: MVC 'best practice' for displaying data

Posted: Wed Dec 01, 2010 3:34 pm
by AbraCadaver
Celauran wrote:And, of course, only now do I see this thread dealing with pretty much the same thing. Sorry.
So from that thread you decided on the view?

Also, I think you should really move the validation to the model. Fat models (business logic), skinny controllers (flow control).

Re: MVC 'best practice' for displaying data

Posted: Wed Dec 01, 2010 3:44 pm
by Celauran
AbraCadaver wrote:So from that thread you decided on the view?
I did.
AbraCadaver wrote:Also, I think you should really move the validation to the model. Fat models (business logic), skinny controllers (flow control).
In this case, at least, 'validation' is basically checking that the fields aren't empty. Checking that $foo is an int as expected, for example, is done within the model's various methods. Think I should move the 'field is not empty' checks to the model as well?

Re: MVC 'best practice' for displaying data

Posted: Wed Dec 01, 2010 4:37 pm
by AbraCadaver
Celauran wrote:
AbraCadaver wrote:So from that thread you decided on the view?
I did.
AbraCadaver wrote:Also, I think you should really move the validation to the model. Fat models (business logic), skinny controllers (flow control).
In this case, at least, 'validation' is basically checking that the fields aren't empty. Checking that $foo is an int as expected, for example, is done within the model's various methods. Think I should move the 'field is not empty' checks to the model as well?
I would. If the business logic of the application dictates that $foo cannot be empty then it goes in the model.