E
E
Elder122015-09-01 21:05:22
Adobe Illustrator
Elder12, 2015-09-01 21:05:22

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

4 answer(s)
S
Sasha Savvov, 2019-03-20
@jeruthadam

blend. Both figures have an equal number of points, then the deformation control is complete.
5c9246b4c09a6313408924.jpeg

D
Denis, 2015-09-02
@prototype_denis

$errors = $this->get('validator')->validate($entity);
if (count($errors) > 0) {
    // errors
}

api.symfony.com/2.0/Symfony/Component/Validator/Va...

A
Alexey Pavlov, 2015-09-01
@lexxpavlov

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.

J
jaxel, 2015-09-02
@jaxel

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 question

Ask a Question

731 491 924 answers to any question