Answer the question
In order to leave comments, you need to log in
How to validate data when using RESTFul api in Symfony2?
Good day, I am implementing my api service, but I don’t know how to check incoming data, I can’t find a clear answer. ParamFetcher is not suitable, because I don’t really want to write regular expressions, so I could use the validator as when checking forms.
Answer the question
In order to leave comments, you need to log in
blend. Both figures have an equal number of points, then the deformation control is complete.
$errors = $this->get('validator')->validate($entity);
if (count($errors) > 0) {
// errors
}
You can make fake forms and use standard validators in them. And you can do it in another way, more interesting - use OptionsResolver - yes, the same ones that are used in forms.
And who prevents you from using the same validator as when working with forms? It is the doctrinal essence that is being validated, not the form itself. Just get the validator as a separate object. You check the doctrine object with the described rules, and everything works exactly like with forms.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question