Answer the question
In order to leave comments, you need to log in
Using DataTransformer in Symfony2?
Faced with the need to use transformers.
Task: to transform object date/time.
The POST request comes with the date/time as a string.
I know that there is a ready solution from Symfony, namely Symfony\Component\Form\Extension\Core\DataTransfor...
When trying to use it,
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$transformer = new DateTimeToStringTransformer();
$builder
->add('caption')
->add('description')
->add($builder->create('startPlan')->addModelTransformer($transformer))
->add('owner')
;
}
Unable to transform value for property path "startPlan": Expected a \DateTime or \DateTimeInterface.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question