Bonjour a tous
j'ai une probleme avec ma twig interface puisque je veux aficher mon entity manytomany sous form d'un table avec un selectbox
mon code est le suivant:
Entity Patient :
<?php
namespace Pediatrie\PediatrieBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* Patient
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Pediatrie\PediatrieBundle\Entity\PatientRepository")
*/
class Patient
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="Nom", type="string", length=255)
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="Prenom", type="string", length=255)
*/
private $prenom;
/**
* @var \DateTime
*
* @ORM\Column(name="Date_Naissance", type="date")
*/
private $dateNaissance;
/**
* @ORM\ManyToMany(targetEntity="Pediatrie\PediatrieBundle\Entity\Allergie", cascade={"persist"})
* @ORM\JoinTable(name="Attaque_Allergies")
*/
private $allergies;
public function __construct()
{
$this->allergies = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
*
* @param Pediatrie\PediatrieBundle\Entity\Allergie $allergies
*/
public function addAllergie(\Pediatrie\PediatrieBundle\Entity\Allergie $allergies)
{
$this->allergies[] = $allergie;
}
/**
*
* @param Pediatrie\PediatrieBundle\Entity\Allergie $allergies
*/
public function removeAllergie(\Pediatrie\PediatrieBundle\Entity\Allergie $allergie) // removeCategorie sans « s » !
{
// Ici on utilise une méthode de l'ArrayCollection, pour supprimer la catégorie en argument
$this->allergies->removeElement($allergie);
}
/**
*
* @return Doctrine\Common\Collections\Collection
*/
public function getAllergies()
{
return $this->allergies;
}
}
Entity Allergie:
<?php
namespace Pediatrie\PediatrieBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Allergie
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Pediatrie\PediatrieBundle\Entity\AllergieRepository")
*/
class Allergie
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="Nom", type="string", length=255)
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="Type", type="string", length=255)
*/
private $type;
/**
* @var string
*
* @ORM\Column(name="Description", type="text")
*/
private $description;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nom
*
* @param string $nom
* @return Allergie
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set type
*
* @param string $type
* @return Allergie
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set description
*
* @param string $description
* @return Allergie
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
}
Ma PatientType :
<?php
namespace Pediatrie\PediatrieBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class PatientType extends AbstractType {
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('nom', 'text', array('label' => 'Nom : ', 'required' => true))
->add('prenom', 'text', array('label' => 'Prénom : ', 'required' => true))
->add('dateNaissance', 'date', array('label' => 'Date naissance : ', 'required' => true))
->add('allergies', 'entity', array(
'class' => 'Pediatrie\PediatrieBundle\Entity\Allergie',
'property' => 'label',
'multiple' => true,
'expanded' => false
))
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Pediatrie\PediatrieBundle\Entity\Patient'
));
}
/**
* @return string
*/
public function getName() {
return 'pediatrie_pediatriebundle_patient';
}
}
Mais au niveau de twig je comprend pas comment faire afficher mon interface des allergies sous la forme suivant :
Merciiiiiii d'avance.