I’m learning MVC to develop a website, and I’m finding confusing the (apparent?) differences from the “theory” and the current widespread implementations.
In the original and Martin Fowler’s article the MVC concept seems to favor a “smart” View, which interacts directly with the Model to retrieve the data to display, and decides by itself how should the data be presented. On the web, that should be the output format (HTML, JSON, PDF, etc).
On the other hand, the View in current frameworks like ASP.NET and Zend seems to be little more than an HTML template.
This to me raises a question: I can create a View for each format, but then where should I in these frameworks decide what View to display? Should the controller decide which View to load? But then, is it the controller’s responsibility to know the right format to display? That seems to be against the theory.
What is your experience when using MVC and you need to output different formats?
My experience with a true MVC is limited to the Zend Framework and I’m still pretty green. But this is my opinion(for what its worth):
In Fowler’s article, he describes an MVC where where the C and V are completely unaware of each other. It is widely excepted that the C and V can interact. See Dean Helman’s explanation and ZF’s explanation.
It has been my experience that the controller can tell the view, for example: “I want this data as JSON” or “Add this data to the navigation” or “Here is the data, I don’t care what you do with it.”