MVC 'best practice' for displaying data

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

MVC 'best practice' for displaying data

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: MVC 'best practice' for displaying data

Post by Celauran »

And, of course, only now do I see this thread dealing with pretty much the same thing. Sorry.
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: MVC 'best practice' for displaying data

Post by s992 »

Well, damn. I was about two seconds away from linking that thread! :D
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: MVC 'best practice' for displaying data

Post 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).
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: MVC 'best practice' for displaying data

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: MVC 'best practice' for displaying data

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply