Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The controller only describes actions on what you need. And it gets data from models via getPropertyObject queries and sets them if you create something new. setPropertyObject. The processing of data correctness itself takes place in the models, as well as the description of the methods of getters and setters. Also in other frameworks there are scripts, AcessControl - access control.
An example of the User model: what controller should it have?
index - what will happen if a person visits the profile page at site.com/user/index/{id of the desired user}
registration - how a new user is created, the form is described inside it.
Login - how the user is authorized, do not confuse with authentication.
Logout - how the user logs out
update - how the user changes his profile
delete - what happens if the user is deleted.
The essence of what is happening: I will try to be very trivial, but I hope you re-read the principle of MVC. A person visits the site at the address, for example, site.com/user/registration
Your User control fires, then comes the registration action (action inside the controller) registration Inside this action, there are two variations of the "page", when the user is not logged in, we show the form, when the user is logged in, there should be no access to the registration function. In the case of a form, the controller generates a form view and waits for the user to fill it out. By clicking on the Submit button, validation is called (the method call itself is written in the controller, but what exactly this method does is written in the model). An instance of the User class is created and filled with data from the form, validated if the validation is successful. it saves to the database and generates a view (page) about success.
As for your "pages" as you can see on one action, there can be many pages and different variations and they do not depend on controllers. Most often, of course, one type for each action, but there are exceptions.
Recommended for viewing:
Here is a self-written MVC, but it is very simple and describes the main idea of this concept, after viewing, you can write your own MVC, but you should not do this. There are enough crutches on the Internet. Just take a look and clarify for yourself some points.
Part 1
Part 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question