I'm currently studying the MVC pattern for PHP but am confused about this aspect:
Is the controller responsible for getting data from the model/s and passing to the view or should the view retrieve data from the model/s directly?
Here are my perceived advantages for each setup:
Controller passes data to view
1) Makes sense that since controller is solely responsible for updating models, then it should also be solely responsible for querying from them
2) In relation to 1), model instances do not have to be injected to views, just the actual data, hence less/no coupling between the two. Controllers are the only components that are "application-aware" as models and views are simply reused/plugged in different applications
3) Views can easily be switched especially if same data is displayed (e.g. different theme/design for the Product page). The controller retrieves the same data from the models and passes to the view regardless of the theme.
4) Views can easily be packaged as HTML files and compartmentalized for the design team while controllers and models are packaged as classes for the development team
View gets data directly from the models
1) Less coupling between controller and view as controller doesn't need to know beforehand data view displays exactly; controller just passes UI input
2) Related to 1), distinctly different views/templates can easily called by the controller with no concern to it since views are responsible for getting whatever data they needs themselves. Consider two versions of the homepage or admin console. Each version can contain different kinds of data and hence, would need different sets of models or model calls depending on which version is used.
3) Views/templates are easier to customize and reuse if you package them as classes with optional setter methods to modify their appearance. If not, each view will have to be split into two files: a) view logic (in PHP) and b) view template (HTML tags with minimal PHP variable displays).
If possible, please provide a framework-agnostic response. Thanks!