this is my controller
public function personnePhysiqueDetailsAction($id)
{
$em = $this->getDoctrine()->getManager();
$controle = $this->get('Controles');
if(($controle->is_Granted('Afficher détail client','Client/Societaire',$this->getUser()))==false){throw new AccessDeniedException();}
// $listePersonnePhysiques=$personnePhysique = $em->getRepository('ITBundle:PersonnePhysique')->findAll();
$personnePhysique = $em->getRepository('ITBundle:PersonnePhysique')->find($id);
$adresses=$em->getRepository('ITBundle:Adresse')->findOneBy(array('personne'=>$personnePhysique));
$mails=$em->getRepository('ITBundle:Email')->findOneBy(array('personne'=>$personnePhysique));
$telephones=$em->getRepository('ITBundle:Telecom')->findBy(array('personne'=>$personnePhysique));
$contrat=$em->getRepository('ITBundle:Contrat')->findBy(array('souscripteur'=>$personnePhysique));
$branches = $em->getRepository('ITBundle:Branche')->findAll();
$compteBancaire=$em->getRepository('ITBundle:CompteBancaire')->findBy(array('personne'=>$personnePhysique));
$avenants=$em->getRepository('ITBundle:AvenantSignaletique')->findBy(array('personne'=>$personnePhysique));
$adresseHisto=$em->getRepository('ITBundle:AdresseHisto')->findBy(array('avenant'=>$avenants));
$compteHisto=$em->getRepository('ITBundle:CompteBancaireHisto')->findBy(array('avenant'=>$avenants));
$personnephysiquehisto=$em->getRepository('ITBundle:PersonnePhysiqueHisto')->findBy(array('avenant'=>$avenants));
$familles=$em->getRepository('ITBundle:Famille')->findBy(array('personne'=>$personnePhysique));
and thid is my repository
public function PersonnePhysiqueDetail($id){
return $this->createQueryBuilder('p')
->select(' p.id, p.nom , p.prenom, p.cin, p.dateNaissance,p.sexe, s.libelle situation,s.id idSituation')
->innerJoin('p.situationFamiliale', 's')
->where('p.id = :idPersonne')
->setParameter('idPersonne', $id)
->getQuery()
->getResult();
}
in my twig
{% for famille in familles %}
<tr>
<th>{{ famille.personne }}:</th>
</tr>
{% endfor %}
this is the declation of familles in my entity personne
/**
* @var array
* @ORM\OneToMany(targetEntity="IT\ITBundle\Entity\Famille",cascade={"persist","remove"}, mappedBy="personne")
* @ORM\JoinColumn(name="enfant_id", referencedColumnName="id")
*/
private $familles;
/**
* Add famille
*
* @param \IT\ITBundle\Entity\Famille $famille
*
* @return Personne
*/
public function addFamille(\IT\ITBundle\Entity\Famille $famille)
{
$this->familles[] = $famille;
return $this;
}
/**
* Remove famille
*
* @param \IT\ITBundle\Entity\Famille $famille
*/
public function removefamille(\IT\ITBundle\Entity\Famille $famille)
{
$this->familles->removeElement($famille);
}
/**
* Get familles
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getfamilles()
{
return $this->familles;
}
and my famille entity is
<?php
namespace IT\ITBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Famille
* @ORM\Table(name="famille")
* @ORM\Entity(repositoryClass="IT\ITBundle\Repository\FamilleRepository")
*/
class Famille
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="lien", type="string", length=255, nullable=true)
*/
private $lien;
/**
* @ORM\ManyToOne(targetEntity="IT\ITBundle\Entity\Personne", inversedBy="familles")
* @ORM\JoinColumn(name="personne_id", referencedColumnName="id")
* #var array
* #ORM\Column(name="personne_id", type="array")
*/
private $personne;
/**
* @var string
* @ORM\ManyToOne(targetEntity="IT\ITBundle\Entity\Personne", inversedBy="familles")
* @ORM\JoinColumn(name="enfant_id", referencedColumnName="id")
*/
private $enfant;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set lien
*
* @param string $lien
* @return Famille
*/
public function setLien($lien)
{
$this->lien = $lien;
return $this;
}
/**
* Get lien
*
* @return string
*/
public function getLien()
{
return $this->lien;
}
/**
* Set personne
*
* @param \IT\ITBundle\Entity\Personne $personne
*
* @return Personne
*/
public function setPersonne(\IT\ITBundle\Entity\Personne $personne = null)
{
$this->personne = $personne;
return $this;
}
/**
* Get personne
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getPersonne()
{
return $this->personne;
}
/**
* Set enfant
*
* @param \IT\ITBundle\Entity\Famille $enfant
*
* @return Personne
*/
public function setEnfant($enfant)
{
$this->enfant = $enfant;
return $this;
}
/**
* Get enfant
*
* @return Personne
*/
public function getEnfant()
{
return $this->enfant;
}
public function __construct()
{
$this->familles = new \Doctrine\Common\Collections\ArrayCollection();
}
}
i know that personne is a array thats makes the problem now i wanna your syggestion please how can i show in my twig 'personne_nom' where id(in personne)= enfant_id(in famille)
To show Personne information, you have to do this
{% for famille in familles %}
<tr>
<th>{{ famille.personne.name }} :</th>
</tr>
{% endfor %}
I wrote name, supposing your personne entity has a name because you didn't show us the full personne entity, but put what you need
with the same entityes and controller code i wanna get teh invers of
{% for famille in familles %}
<tr>
<th>{{ famille.personne.name }} :</th>
</tr>
{% endfor %}
i mean show the name of personne and there chidren when ((id-enfant) 'famille table')equale to ((id) in personne table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.