• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MVC best practices, to display the models

#12
[eluser]Mirage[/eluser]
You're right - you're facing a dilemma because you're attempting to have the model 'output itself'. Get rid of that thought pattern and the fog will lift... Models aren't supposed to output themselves.

You correctly identified two main schools of thought. And the Model is neutral in both. It provides business data, plain and simple - regardless whether queried by a controller or a view-script.

Which method to use for display may depend a lot on what else needs to be done. Perhaps the single model call is not enough to supply all the data a view might need and you need to query additional models to retrieve related data. Once that happens, you start dealing with error logic, because there is no guarantee that the model will provide data that let's you go further in your script and you may want to output a warning or something. If you're already in the view - while possible - it's a bit late to switch gears and ultimately you could end up with a jumble of checks in all kinds of places.

That's why I tend to stick with approach #1.

HTMS,
-m


Messages In This Thread
MVC best practices, to display the models - by El Forum - 09-20-2008, 05:06 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 06:50 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 10:47 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 10:56 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 11:24 PM
MVC best practices, to display the models - by El Forum - 09-20-2008, 11:57 PM
MVC best practices, to display the models - by El Forum - 09-21-2008, 12:22 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 02:56 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 03:21 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 03:25 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 11:40 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 12:06 PM
MVC best practices, to display the models - by El Forum - 09-21-2008, 12:23 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.