3

Is there any way to hydrate entities with json data from an incoming request in Symfony2? I thought there was something similar to

Form::bindRequest

But I can't find anything... It would be nice to have this feature for using with libraries like knockout js.

1 Answer 1

4

If what you need is to hydrate objects from a JSON (or XML) format, you can take a look at the Serializer component.

It was made to solve this kind of common problem.

You can even try the JMSSerializerBundle that makes the use of this component easier.

About validation, as it's another component (Validator), you can use it appart of the forms:

$validator = $this->get('validator');
$violdations = $validator->validate($myModel);

if (0 === $violations->count()) {
    // ok !
} else {
    // there are some constraint violations...
} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.