I am using this cookbook recipe to add a data transformer in Symfon 2.1, but I am getting the following error, The option "em" does not exist. Known options are: "attr", "block_name",....
Is this still a valid way to send the entity manager over to the form type?
$taskForm = $this->createForm(new TaskType(), $task, array(
'em' => $this->getDoctrine()->getEntityManager(),
));
To make the first simple (without dependency injection) Transformer's cookbook recipe work you should add "em" as a known option. You can add it in your form's type class (TaskType in cookbook case) using setRequired()
method like this:
class TaskType extends AbstractType {
//...
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
//...other stuff like $resolver->setDefaults(... if you need it
$resolver->setRequired(array('em'));
}
}
Adding 'em' with $resolver->setDefaults() would also work, but in this cookbook case entity manager is needed and so using setRequired() seems better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With