I'm trying to set a form type "sonata_type_immutable_array" as follows:
->add('metadatos', 'sonata_type_immutable_array', array(
'keys' => array(
array('Test', 'text', array('required' => false)),
array('URL', 'url', array('required' => false)),
)
))
And saving like this:
public function setMetadatos(\Portal\EntradasBundle\Entity\EntradaMeta $metadatos = null)
{
$this->metadatos = $metadatos;
return $this;
}
But always get the error:
Catchable Fatal Error: Argument 1 passed to Portal\EntradasBundle\Entity\Entrada::setMetadatos() must be an instance of Portal\EntradasBundle\Entity\EntradaMeta, array given
I dont know how to set a datatransformer (ArrayToModelTransformer) to reach this.
Anyone can help me plz. Thanks in advance!
A data transformer is quite simple, Look at this: http://symfony.com/doc/current/cookbook/form/data_transformers.html
A data transformer is used like this:
/**
* @var ObjectManager
*/
private $om;
/**
* @param ObjectManager $om
*/
public function __construct($om)
{
$this->om = $om;
}
[..]
$yourTransformer = new YourDataTransformer($this->om);
And then ->addModelTransformer($yourTransformer))
It's used to get the id of an object , and/or get the object from an id.
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