php - Should you validate in the Model? (Symfony based question, but related to general MVC) -


This is a quick question related to symphony, but there may be a general MVC question.

I have a class in my model, for example, WebUser is a property of email_address in this class. This value is being used for each WebUser should be unique to.

Now, I have made it so that all my symphony forms can be validated that email_address is unique WebUser given, but I think Should I add this recognition to the model too?

But I was also thinking, should you actually validate each set () method in the model? It seems that there is an intelligent enough decision to not get rid of any wrong data in the database, although most (if not all) data is to go through the controllers, which is valid then it seems to me that I am the same I am running the recognition twice and it just seems useless?

What are your thoughts on this? I am still bending towards the verification in the model because it makes the most sense because it gives a business logic.

If you want to be valid in the model, then you have an appropriate set ()

>

I agree "Validation should be a part of the domain logic, not with front end logic".

Verification is a complex functional part of your application and should reference should be familiar, i.e. You need to know that the user is logged in, what kind of credentials, the status of the request / form and so on. Anonymity of reference should instead of the model (not only CLI etc. on HTTP requests to work in any environment) so that they do not know about user, state, and http request. This is a strong requirement for testability of your model sections.

Functional verification for the reason explained is related to the form that the application knows the state (i.e. session). Symfony sfValidator * helps a lot with the classes that are actually related to the form component, this is why the form is tested with the functional test.

Data validation should be in the model instead (i.e. check that the value is an integer or string, check whether it is zero and so on). It is easily done in principle with the schema validation rules.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -