In the user model, I describe the registration method. Can I directly interact with the $ _POST` array from this method and write data to the session when the registration is successful?

Or do I need to transfer the form data to the registration method in the controller, and after receiving the registration result, write the data to the session?

And another question: who should deal with data validation - a model or a controller? I validated the data in the model's setters, i.e. Before writing down any property of a user, be it a name or email, the data in the corresponding setter is first checked. It is acceptable?

  • one
    I highly recommend reading habr.com/post/321050 and half the questions will disappear by itself. - Lexx918
  • one
    In general, pure MVC raises many questions in terms of what should be, but of course it’s worth using as a basis. And now for your questions: Can the model work with a post - no. with cookies - no. In fact, a model is only a set of functions, the task of which is получить some data, process it, and give an answer, so the post array is passed as a parameter. and the assignment of cookies is the controller's task. Validate will be engaged in the model. Use in the setter - no, you communicate with the model only through its functions, there is a check, and not specifically with variables. - Manitikyl

1 answer 1

Why not in the model? A model is a library of methods. Describe this method in it and then call it in the controller via the model object. In the session it is better to record of course after a successful registration. Make it in the controller, you can also create cookies. The validation method is again described in the model, and is called in the controller.