Hello
Avant sous sf2 je faisais ca :
Maintenant on doit faire ça
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 $search_form = $this->createForm(new SearchType($em), $data, array( 'action' => $this->generateUrl('document'), 'method' => 'GET', ));
Dans la doc il disent de passer par un service (pas cool :-( )
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 $search_form = $this->createForm(SearchType::class, $data, array( 'action' => $this->generateUrl('document'), 'method' => 'GET', ));
Donc j'ai fait ca
Et puis dans mon controller ??
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 services: app.form.type.search: class: GenealogieBundle\Form\SearchType arguments: ["@doctrine.orm.entity_manager"] tags: - { name: form.type }
Mais ça plante :-(
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 $search_form = $this->get('app.form.type.search');
Mon formulaireAttempted to call an undefined method named "handleRequest" of class "GenealogieBundle\Form\SearchType".
Merci
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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <?php class SearchType extends AbstractType { protected $em; function __construct(EntityManager $em) { $this->em = $em; } /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->add('commune')->add('submit', 'submit', array( 'label' => 'Rechercher', )) ->add('raz', 'submit', array( 'label' => 'raz.button', 'attr' => array('class' => 'btn-sm btn-success', 'title' => 'Search raz'))); } /** * @param OptionsResolver $resolver */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'GenealogieBundle\Entity\Acte' )); } }
Partager