Bonjour,
Comment puis-je faire pour afficher des champs de type collection pré remplis ?
Lorsque j'hydrate mon formulaire :
J'obtiens l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public function testAction($action, $id){ (...) $em = $this->getDoctrine()->getManager(); //Service EntityManager $a = $em->getRepository('StcTestBundle:Article')->find($id); $form = $this->createForm(new ArticleType, $a); //CREATION FORM GENERIQUE HYDRATE (...) }
Formulaire ArticleType"The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class Stc\testBundle\Entity\Article.
You can avoid this error by setting the "data_class" option to "Stc\testBundle\Entity\Article" or
by adding a view transformer that transforms an instance of class Stc\testBundle\Entity\Article
to scalar, array or an instance of \ArrayAccess."
Formulaire LienType
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 class ArticleType extends AbstractType{ (..) ->add('liens', 'collection', array('type'* => new LienType(), 'allow_add'*** => true,'allow_delete' => true)) }
Cdlt
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 class LienType extends AbstractType{ public function buildForm(FormBuilderInterface $builder, array $options){ $builder ->add('url', 'url', array('default_protocol' => 'http', 'max_length' => 120, 'required' => true, 'label' => false, 'trim' => true)) ->add('article','hidden') ; } public function setDefaultOptions(OptionsResolverInterface $resolver){ $resolver->setDefaults(array('data_class' => 'Stc\TestBundle\Entity\Lien')); } public function getName() { return 'test_lien'; } }
Partager