Whose duty is it to check the variables(isset)?

Write a simple registration, the question is.

I have a model that says the registration method, the method also there is a check on whether the button is pressed, boxes have been populated. From the point of view of mvc, validation, isset should not be in the model? They are probably better in the controller to make?
April 4th 20 at 00:50
3 answers
April 4th 20 at 00:52
in MVC there is no clear definition where to include validation. At the same time, MVC does not describe absolutely the entire application, only the idea. The popular frameworks of type Symfony and Zend have a special thing up in the array came the data, and return the completed object, if the data passed validation, or return an array of errors. Often practice using the form in the controller: there sefatsa data from request into the form, then the form check for errors and if any, the controller returns an error message, otherwise takes the completed data object and passes it to the service.
April 4th 20 at 00:54
This is a complex issue, but the scheme that I will write, least problematic, especially during long projects.

It is the responsibility of the assembler, which assembles a typed request object. And it's not a Entity/Model, even if the fields are almost identical, it is a separate DTO.
The controller gets this typed query object.

If the data in the wrong format (error front-end, not user input), the controller they don't even get.

Controller they are already validated by the validator and transmits to the model. Correspondingly, if the data is not passed validation on controller, in the model they will not get.

Moreover, at the model level can have its own validation, because the data can come not only from the controller and commands.

However, if you have a simple script with two parameters, which are thrown, it is correct to hammer on these architectural masterpieces and simply get the field from the query.
April 4th 20 at 00:56
From the point of view of mvc, validation, isset should not be in the model? They are probably better in the controller to make?
It is better that the website was almost (or quite) crashproof, put them in the filter user input: the root level and immediately check for validity, and only then to pass to the routing web application.

Use the validation regex+preg_match() (the clouds instead of isset() in different places of code) to know the array of all input variables to preset values and to minimize the risks and burden.
What? - Guiseppe.Bechtelar commented on April 4th 20 at 00:59
@Wilhelmine_Ri, he has in mind mallware, it seems. But he wrote complicated, Yes) - ila44 commented on April 4th 20 at 01:02
@Deonte.Sau, don't know anything about midleware)
The request came in we immediately analyze the validity of the data you expect before something to do with it.
If at least one parameter does not pass such a test - no ranting on and, moreover, no apps, models, controllers and isset () s.

It is impossible to give the raw data for the validation in the application using Routh: hence all the "holes". - Katelyn_Lakin commented on April 4th 20 at 01:05
@Wilhelmine_Ri, root is not root, and the upper/primary level of handling a user request. - Katelyn_Lakin commented on April 4th 20 at 01:08
This is mallware) - ila44 commented on April 4th 20 at 01:11
The toaster is now "curator" to the left and right hand out. - paula.Ste commented on April 4th 20 at 01:14
@rick_Lehner,
The toaster is now "curator" to the left and right hand out.
flown, che did not grab something for myself too?) - Katelyn_Lakin commented on April 4th 20 at 01:17

Find more questions by tags PHP