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.
MVC 'best practice' for displaying data
Moderator: General Moderators
Re: MVC 'best practice' for displaying data
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
Well, damn. I was about two seconds away from linking that thread! 
- 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
So from that thread you decided on the view?Celauran wrote:And, of course, only now do I see this thread dealing with pretty much the same thing. Sorry.
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.
Re: MVC 'best practice' for displaying data
I did.AbraCadaver wrote:So from that thread you decided on the view?
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?AbraCadaver wrote:Also, I think you should really move the validation to the model. Fat models (business logic), skinny controllers (flow control).
- 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
I would. If the business logic of the application dictates that $foo cannot be empty then it goes in the model.Celauran wrote:I did.AbraCadaver wrote:So from that thread you decided on the view?
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?AbraCadaver wrote: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.