0
 class Location
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column()]
private ?int $id = null;

#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $FromDate = null;

#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $ToDate = null;

#[ORM\Column]
private ?float $Remise = null;

#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
private ?User $Id_User = null;

#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?Vehicule $Id_Vehicule = null;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $DateRegistration = null;

/*#[ORM\ManyToOne]
private ?Reservation $Id_Reservation = null;*/


#[ORM\Entity(repositoryClass: VehiculeRepository::class)]
   class Vehicule
 {
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column()]
private ?int $id = null;

#[ORM\Column(length: 255)]
private ?string $Titre = null;

#[ORM\Column(type: Types::TEXT)]
private ?string $Description = null;

#[ORM\Column]
private ?float $PrixDay = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $ImageFront = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $ImageBack = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $ImageSide = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $ImageInside = null;

#[ORM\Column]
private ?int $ModelYear = null;

#[ORM\Column]
private ?int $Capacity = null;

#[ORM\Column(length: 50)]
private ?string $StatusVehicule = null;

#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $DateRegistration = null;

#[ORM\ManyToOne]
private ?TypeVehicule $Id_TypeVehicule = null;

#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?Marque $Id_Marque = null;

#[ORM\Column(length: 255)]
private ?string $Model = null;

#[ORM\Column(length: 255)]
private ?string $Matricul = null;


#[ORM\Entity(repositoryClass: UserRepository::class)]
 class User
 {
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column()]
private ?int $id = null;

#[ORM\Column(length: 255)]
private ?string $Nom = null;

#[ORM\Column(length: 255)]
private ?string $Prenom = null;

#[ORM\Column(length: 255)]
private ?string $Email = null;

#[ORM\Column(length: 255)]
private ?string $Password = null;

#[ORM\Column(length: 255)]
private ?string $Cin = null;

#[ORM\Column(length: 255)]
private ?string $Adresse = null;

I want to list all entities in a view from a table (location) which needs a join to display some details (vehicule and user). I used the createQuery to get data from database.

Below is a basic controller example. My problem is that it is can i display the result in the twig page?

//controller: 
#[Route('/listLocation', name: 'listLocation')]
public function listLocation(ManagerRegistry $doctrine, Request $request,LocationRepository $locationRepository, UserRepository $userRepository, ClientRepository $clientRepository, VehiculeRepository $vehiculeRepository): Response
{
    $entityManager = $doctrine->getManager();
    $locations = $entityManager->createQuery("SELECT l, v, u FROM App\Entity\Location l JOIN l.Id_Vehicule v JOIN l.Id_User u ORDER BY l.DateRegistration ")->getResult();
    return $this->render('back/location/listLocation.html.twig', [
        'locations' => $locations,
    ]);
}

 //twig
 <thead>
        <th>N° Location</th>
        <th>Client</th>*** from the client table***
        <th>CIN</th>*** from the client table***
        <th>Vehicule</th>+++from the vehicule table+++
        <th>Matricule</th>+++ from the vehicule table+++
        <th>Periode</th>
        <th>Total</th>
    </thead>
    <tbody>
    {% for location in locations %}
        <tr>
            <td>{{location.id}}</td>
    ********<td>{{location.Id_Client.Nom}} {{location.Id_Client.Prenom}} </td>
    ********<td>{{location.Id_Client.Cin}}</td>
    ********<td>{{location.Id_Vehicule.Titre}}</td>
    ********<td>{{location.Id_Vehicule.Matricule}}</td> 
            <td>De: {{location.FromDate|date('Y-m-d H:i:s')}} à           
  {{location.ToDate|date('Y-m-d H:i:s')}}</td>
            <td>{{location.Remise}}</td>
            <td><pre>
                {{ dump(location) }}
            </pre></td>
        </tr>
    {% endfor %}
    </tbody>

ps: i have problem in the ***** places

  • You should add the entities as well so people can see which kind of relations you have defined between the different entities – DarkBee Aug 11 '22 at 06:05
  • [Related question](https://stackoverflow.com/questions/25126208/symfony-2-how-to-display-joined-doctrine-entities-in-twig-template) – DarkBee Aug 11 '22 at 06:11

0 Answers0