2012-11-03 6 views
5

che sto cercando di impostare un tipo di modulo "sonata_type_immutable_array" come segue:Symfony2 Sonata amministratore datatransformer

->add('metadatos', 'sonata_type_immutable_array', array(
    'keys' => array(
        array('Test', 'text', array('required' => false)), 
        array('URL', 'url', array('required' => false)), 
       ) 
      )) 

e il salvataggio in questo modo:

public function setMetadatos(\Portal\EntradasBundle\Entity\EntradaMeta $metadatos = null) 
{ 
    $this->metadatos = $metadatos; 

    return $this; 
} 

Ma sempre ottenere l'errore:

Errore irreversibile Catchable: l'argomento 1 passato a Portal \ EntradasBundle \ Entity \ Entrada :: setMetadatos() deve essere un'istanza di Portal \ EntradasBundle \ Entity \ EntradaMeta, array dato

Non so come impostare un datatransformer (ArrayToModelTransformer) per raggiungere questo.

Chiunque può aiutarmi. Grazie in anticipo!

risposta

1

Un trasformatore di dati è abbastanza semplice, Guardate questa: http://symfony.com/doc/current/cookbook/form/data_transformers.html

Un trasformatore dati vengono usati in questo modo:

/** 
    * @var ObjectManager 
    */ 
    private $om; 

    /** 
    * @param ObjectManager $om 
    */ 
    public function __construct($om) 
    { 
     $this->om = $om; 
    } 

[..] 
$yourTransformer = new YourDataTransformer($this->om); 

And then ->addModelTransformer($yourTransformer)) 

E 'usato per ottenere l'id di un oggetto, e/o ottenere l'oggetto da un id.