Answer the question
In order to leave comments, you need to log in
What is the difference between a controller and an action?
Guys, please explain once. How do they differ? On the example of a specific site.
Here is a website with two pages. On one user management /users/. The second is the product table /products/.
That's it, there's nothing else on the site. Internal system.
Do I understand correctly that only actions are used here?
Question about MVC.
Answer the question
In order to leave comments, you need to log in
A little about sore points:
There are no actions in MVC. MVC works in the following way:
- The model is located in the view (for example, "text field")
- Any changes in the model immediately change the view (we change the text in the text field and this text is rendered / rendered)
- The controller subscribes to view events (for example, "text change in the text field") and performs some action, including changing the models (well xs, for example, checking that the length is no more than 10 characters. Or another example. The controller subscribes to the "delete" button click event and deletes the text from the text field model , and the model is immediately redrawn, since it is directly related to the view).
All this is perfectly visible in the picture, which is taken from the wiki:https://ru.wikipedia.org/wiki/Model-View-Controller
On the web, the implementation of MVC without sockets is not physically possible (which, by the way, in the 80s-90s was called MVCE: Model-View-Controller-Editor, not essence). Most of the existing solutions are variations of the MVP (Laravel/Symfony/etc) with little nuances. The controller is called controllers there, and not a presenter according to the GRASP principle and is not related to MVC in any way.
BUT. There is such a thing as collective opinion. For example, according to the rules of the Russian language, you can write "parachute" and not "parachute" starting from some 2010 there. This is now the norm. Xs. In short, illiterate ignoramuses are fucked up. And because there are really fucking people who can’t tell one from the other and not be an ignoramus, then we decided that we’ll call this business “MVC with passive models”, because it’s too difficult to call this approach MVP, you need to read it more, learn, better we will throw terms, they will think that it is smart.
So here's what I'm getting at. The classic MVP on the web is inconvenient (which can be seen in the examples of the first Zend, Phalcon and other tenets), so they added a layer in the form of a router that says: "At /users with a GET request, send me to this class and execute this method", for example: "$router->get('/users', 'UserClass', 'action')". The method itself returns the desired view with data and is called "action", and the class that contains a set of these same "actions" is called "controller" or "presenter". In the view, with the help of cheats (template engine), you can specify, for example, which header / footer (layout) to use, which title, and so on. Thus, we get different pages at different addresses with different data,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question