Comment passer un argument du controleur à la class du formulaire
Bonjour,
J'ai une class de formulaire :
Code:
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
|
namespace Amb\CreditBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class EncaissementType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('n_quitance', 'integer')
->add('mode_encaissement', 'choice', array(
'choices' => $mode_encaissement, 'data' => 1))
->add('type_encaissment', 'text')
->add('montant', 'money', array('precision' => 2, 'required' => true))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Amb\CreditBundle\Entity\Encaissement'
));
}
public function getName()
{
return 'amb_creditbundle_encaissementtype';
}
} |
et j'ai une méthode dans mon controleur :
Code:
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 41 42 43 44 45 46 47 48 49
|
public function add_encaissementAction($appt)
{
$adhesion = $this->getDoctrine()
->getRepository('AmbAdherentBundle:Adhesion')
->find($appt);
if($adhesion != null)
{
$encaissement = new encaissement();
$adherent = $adhesion->getAdherent();
$encaissement->setDateOperation(new \Datetime());
$encaissement->setAdhesion($adhesion);
$encaissement->setAdherent($adherent);
$ambexceldb = $this->container->get('amb_credit.ambexceldb');
$mode_encaissement = array(1 => 'choix1', 2 => 'choix2', 3 => 'choix3');
$form = $this->createForm(new EncaissementType, $encaissement);
$request = $this->get('request');
if( $request->getMethod() == 'POST' )
{
$form->bind($request);
if( $form->isValid() )
{
$em = $this->getDoctrine()->getEntityManager();
$em->persist($encaissement);
$em->flush();
$encaissements = $adhesion->getEncaissements();
return $this->redirect( $this->generateUrl('ambcredit_listversement', array(
'appt' => $appt,
'adherent' => $adherent,
'adhesion' => $adhesion,
'encaissements' => $encaissements
)));
}
}
}
return $this->render('AmbCreditBundle:Encaissement:add_encaissement.html.twig', array(
'form' => $form->createView()
));
} |
le problème ce que je veux passer le tableau $mode_encaissement (la ligne 19 de mon controleur) a ma class de formulaire (la ligne 16) , est je sais pas comment ?
Est ce que quelqu'un peut m'aider SVP?
la version du symfony est : 2.1.4