Bonjour,



Je recherche à personnaliser dans mon formulaire, un champ de type Entity.

Je récupère bien ma classe avec le champ à afficher dans mon select mais je souhaiterai afficher 2 champs et non un.



Je possède 2 entités avec jointures entre operation et indicateur.

Mon entité Indicateur :

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
 
namespace ApplicationBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
 
/**
 * ApplicationBundle\Entity\Indicateur
 *
 * @ORM\Table(name="Indicateur")
 * @ORM\Entity(repositoryClass="ApplicationBundle\Repository\IndicateurRepository")
 */
class Indicateur
{
    /**
     * @var integer $idIndicateur
     *
     * @ORM\Column(name="id_indicateur",type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $idIndicateur;
 
    /**
     * @ORM\ManyToOne(targetEntity="ApplicationBundle\Entity\Secteur")
     * @ORM\JoinColumn(name="id_secteur", referencedColumnName="id_secteur", nullable=false)
     */
    private $idSecteur;
 
    /**
     * @var string $libelle
     *
     * @ORM\Column(name="libelle", type="string", length=50, nullable=false)
     * @Assert\NotBlank()
     */
    private $libelle;
 
    /**
     * @var integer $indice
     *
     * @ORM\Column(name="indice", type="integer", nullable=true)
     */
    private $indice;
 
    /**
     * @var integer $niveau
     *
     * @ORM\Column(name="niveau", type="integer", nullable=false)
     */
    private $niveau;
 
    /**
     * @var integer $poids
     *
     * @ORM\Column(name="poids", type="integer", nullable=true)
     */
    private $poids;
 
     /**
     * @var date $date
     *
     * @ORM\Column(name="date", type="date", nullable=true)
     */
    private $date;
 
    /**
     * @var boolean $visuel
     *
     * @ORM\Column(name="visuel", type="boolean")
     */
    private $visuel;
 
        /**
     * @var boolean $chiffre
     *
     * @ORM\Column(name="chiffre", type="boolean")
     */
    private $chiffre;

Entité Operation :

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
 
namespace ApplicationBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
 
/**
 * ApplicationBundle\Entity\Operation
 *
 * @ORM\Table(name="Operation")
 * @ORM\Entity(repositoryClass="ApplicationBundle\Repository\OperationRepository")
 */
class Operation
{
    /**
     * @var integer $idOperation
     *
     * @ORM\Column(name="id_operation",type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $idOperation;
 
    /**
     * @ORM\ManyToOne(targetEntity="ApplicationBundle\Entity\Indicateur")
     * @ORM\JoinColumn(name="id_indicateur", referencedColumnName="id_indicateur", nullable=false)
     */
    private $idIndicateur;
 
    /**
     * @var string $operation
     *
     * @ORM\Column(name="operation", type="string", length=50, nullable=false)
     */
    private $operation;
 
    /**
     * @var float $borne1
     *
     * @ORM\Column(name="borne1", type="float", nullable=true)
     */
    private $borne1;
 
    /**
     * @var float $borne2
     *
     * @ORM\Column(name="borne2", type="float", nullable=true)
     */
    private $borne2;
 
    /**
     * @var float $borne3
     *
     * @ORM\Column(name="borne3", type="float", nullable=true)
     */
    private $borne3;
 
    /**
     * @var float $borne4
     *
     * @ORM\Column(name="borne4", type="float", nullable=true)
     */
    private $borne4;
 
    /**
     * @var string $feu1
     *
     * @ORM\Column(name="feu1", type="string", nullable=true)
     */
    private $feu1;
 
     /**
     * @var string $feu2
     *
     * @ORM\Column(name="feu2", type="string", nullable=true)
     */
    private $feu2;
 
    /**
     * @var string $feu3
     *
     * @ORM\Column(name="feu3", type="string", nullable=true)
     */
    private $feu3;
 
    /**
     * @var string $feu4
     *
     * @ORM\Column(name="feu4", type="string", nullable=true)
     */
    private $feu4;

Pour afficher que le libelle dans mon formulaire Operation ca fonctionne parfaitement, mais comment puis je faire pour afficher le libelle et un deuxième champs?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
->add('idIndicateur', 'entity', array('label'=>'Indicateur',
                                            'class' => 'ApplicationBundle:Indicateur',
                                            'property' => 'libelle',
                                            'multiple' => false,
                                            'empty_value' => '',
                                            'empty_data'  => '',
                                            'required' => true,
                                            'query_builder' => function(EntityRepository $er){
                                                return $er->createQueryBuilder('s')->orderBy('s.libelle','ASC');
                                                }
                                            ))

J'ai testé de la facon suivante mais ca me rejette lors de la vérification de mon formulaire car dans mon entité j'ai une jointure many to one sur idIndicateur.

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
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        //Liste des indicateurs
        $maListeIndicateur=array();
        $listIndicateur = $this->em->getRepository('ApplicationBundle:Indicateur')->createQueryBuilder('p')
            ->leftJoin('p.idSecteur', 'c')
                ->addOrderBy('c.libelle', 'asc')
                ->addOrderBy('p.niveau', 'asc')
                ->addOrderBy('p.libelle', 'asc')
                ->getQuery()
                ->getResult()
                ;
 
        foreach($listIndicateur as $indicateur){
            $maListeIndicateur[$indicateur->getIdIndicateur()]=$indicateur->getIdSecteur()->getLibelle()." - ".$indicateur->getLibelle()." (n".$indicateur->getNiveau().")";
        }
 
$builder
->add('idIndicateur', 'choice',  array( 'label' => 'Indicateur',
                                            'choices' =>$maListeIndicateur,
                                            'multiple' => false,
                                            'empty_value' => '',
                                            'empty_data'  => '',
                                            'required' => true))
Comment puis je faire svp?



Merci