I’ve read up a bit on the concept of MVC and have used it in the past, but feel as if I do not firmly understand where responsibilities lie.
Can someone tell me what I’m missing after reading my interpretation of MVC?
The Model represents the data, and performs all of the heavy lifting.
The Controller forms a bridge between user requests and Model functions.
The View contains layout and presentation representations, and should be as dumb as possible.
The View and the Model can both request actions of the Controller.
The primary role of the Controller in the context of Yii is to perform access control.
The View should attempt to minimize calls to the Model directly, instead going through the Controller.
Is there anything glaring about the following example?
I have a view that presents a list of models in tabular form. Each row of the table has a drop-down box. The drop-down box allows the user to change the state of a model or generate a PDF representation of the model directly in the browser.
The way I have it set up, the name of each drop-down box contains the id of its database record (i.e. dropdownbox1 for id=1). Thus, I can tell which record should be subject to the action submitted. The problem is that the action to be requested of the controller is dependent on the value of the drop-down box.
Here’s the way I’ve set it up:
In the first few lines of the view, I
-Check to see if $_POST contains anything
-The controller calls Model::processPost()
-The model changes its state if the value of the drop down box is between 1 and 3
-Otherwise, the model calls redirect(‘controller/generatepdf’)
Thanks for reading my wordy post.