I'm trying to get a clear grasp on MVC architecture, but there are two completely different views (no pun intended) of MVC.
1) An example of the MVC I learned is here in Apple's developer documentation. This should logically be called "Model-Controller-View," because the View and Model never touch. The Controller passes input and output between them.
-My first MVC app was written like that: The "Model" class had properties that matched columns in a database table. The "Controller" class instantiated arrays of "Models" from the results of SQL queries. The "Model" class had methods to CRUD database entries, but the "Controller" class called those methods. The "View" class built a table and displayed the Model objects the Controller class passed to it.
2) A different example is in the Wikipedia article on MVC. Here, the Model sits in between the View and the Controller. The Controller updates the Model, which in turn feeds data to the View. It's almost like the Controller is Input and the View is Output.
-I've built some PHP websites like this (I think). Data was built from custom classes instantiated in $_SESSION variables. One set of PHP files had the HTML needed to display the $_SESSION data to the user. They made AJAX calls to "Controller" PHP files that updated the $_SESSION variables but didn't produce HTML. In that respect, the Model ($_SESSION) sent data to the View (the PHP with HTML the user saw) and was updated by the Controller (the PHP that CRUD'd $_SESSION).
-------------------------------------
I probably made mistakes there. Please (constructively) correct me.
It seems like there's an ongoing flame war between devotees of one definition and the other. I've found dueling articles arguing back and forth about which element sits in the middle: Model or Controller. See this example from Coding Horror. The author uses HTML, CSS, and the browser as examples of Model, View and Controller. But commenters immediately take exception, and long argument about the "true" definition of MVC ensues.
What's the Ars opinion? In MVC, does the Controller pass data between the View and Model? Or does the Model take from Controller and give to View?
1) An example of the MVC I learned is here in Apple's developer documentation. This should logically be called "Model-Controller-View," because the View and Model never touch. The Controller passes input and output between them.
-My first MVC app was written like that: The "Model" class had properties that matched columns in a database table. The "Controller" class instantiated arrays of "Models" from the results of SQL queries. The "Model" class had methods to CRUD database entries, but the "Controller" class called those methods. The "View" class built a table and displayed the Model objects the Controller class passed to it.
2) A different example is in the Wikipedia article on MVC. Here, the Model sits in between the View and the Controller. The Controller updates the Model, which in turn feeds data to the View. It's almost like the Controller is Input and the View is Output.
-I've built some PHP websites like this (I think). Data was built from custom classes instantiated in $_SESSION variables. One set of PHP files had the HTML needed to display the $_SESSION data to the user. They made AJAX calls to "Controller" PHP files that updated the $_SESSION variables but didn't produce HTML. In that respect, the Model ($_SESSION) sent data to the View (the PHP with HTML the user saw) and was updated by the Controller (the PHP that CRUD'd $_SESSION).
-------------------------------------
I probably made mistakes there. Please (constructively) correct me.
It seems like there's an ongoing flame war between devotees of one definition and the other. I've found dueling articles arguing back and forth about which element sits in the middle: Model or Controller. See this example from Coding Horror. The author uses HTML, CSS, and the browser as examples of Model, View and Controller. But commenters immediately take exception, and long argument about the "true" definition of MVC ensues.
What's the Ars opinion? In MVC, does the Controller pass data between the View and Model? Or does the Model take from Controller and give to View?