Bonjour à tous, je voudrait fusionner 2 tables et l'afficher dans ma vue avec twigs. J'ai 2 tables, l'une avec les taux de tva et l'autre avec les intitulé des comptes.
Voivi mon Entité taux tva
<?php
namespace App\Entity;
use App\Repository\TauxTvaRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=TauxTvaRepository::class)
*/
class TauxTva
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tauxtva;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $compte;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $taux;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $intitule;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
/**
* @ORM\ManyToOne(targetEntity=Plancomptable::class)
*/
private $relation;
public function getId(): ?int
{
return $this->id;
}
public function getTauxtva(): ?string
{
return $this->tauxtva;
}
public function setTauxtva(?string $tauxtva): self
{
$this->tauxtva = $tauxtva;
return $this;
}
public function getCompte(): ?string
{
return $this->compte;
}
public function setCompte(?string $compte): self
{
$this->compte = $compte;
return $this;
}
public function getTaux(): ?string
{
return $this->taux;
}
public function setTaux(?string $taux): self
{
$this->taux = $taux;
return $this;
}
public function getIntitule(): ?string
{
return $this->intitule;
}
public function setIntitule(?string $intitule): self
{
$this->intitule = $intitule;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getRelation(): ?Plancomptable
{
return $this->relation;
}
public function setRelation(?Plancomptable $relation): self
{
$this->relation = $relation;
return $this;
}
}
Mon entité plan comptable
<?php
namespace App\Entity;
use App\Repository\PlancomptableRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=PlancomptableRepository::class)
*/
class Plancomptable
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $compte;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $compteperso;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $intitule;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $classe;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tva;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $differe;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sousclasse;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sousclassedec;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $comptepremier;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $debitcredit;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="plancomptables")
*/
private $user;
public function getId(): ?int
{
return $this->id;
}
public function getCompte(): ?string
{
return $this->compte;
}
public function setCompte(?string $compte): self
{
$this->compte = $compte;
return $this;
}
public function getCompteperso(): ?string
{
return $this->compteperso;
}
public function setCompteperso(?string $compteperso): self
{
$this->compteperso = $compteperso;
return $this;
}
public function getIntitule(): ?string
{
return $this->intitule;
}
public function setIntitule(?string $intitule): self
{
$this->intitule = $intitule;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getClasse(): ?string
{
return $this->classe;
}
public function setClasse(?string $classe): self
{
$this->classe = $classe;
return $this;
}
public function getTva(): ?string
{
return $this->tva;
}
public function setTva(?string $tva): self
{
$this->tva = $tva;
return $this;
}
public function getDiffere(): ?string
{
return $this->differe;
}
public function setDiffere(?string $differe): self
{
$this->differe = $differe;
return $this;
}
public function getSousclasse(): ?string
{
return $this->sousclasse;
}
public function setSousclasse(?string $sousclasse): self
{
$this->sousclasse = $sousclasse;
return $this;
}
public function getSousclassedec(): ?string
{
return $this->sousclassedec;
}
public function setSousclassedec(?string $sousclassedec): self
{
$this->sousclassedec = $sousclassedec;
return $this;
}
public function getComptepremier(): ?string
{
return $this->comptepremier;
}
public function setComptepremier(?string $comptepremier): self
{
$this->comptepremier = $comptepremier;
return $this;
}
public function getDebitcredit(): ?string
{
return $this->debitcredit;
}
public function setDebitcredit(?string $debitcredit): self
{
$this->debitcredit = $debitcredit;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}
Mon controleur
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\TauxTva;
class TabController extends AbstractController
{
/**
* @Route("/", name="home")
*/
public function index()
{
$products = $this->getDoctrine()
->getRepository(TauxTva::class)
->findAll();
return $this->render('tab.html.twig', array("user" => $products));
}
}
Et enfin ma vue, la ou je voudrait fusionner pour afficher l'intitulé du compte qui ce trouve dans la table plancomptable.
<h1>Members</h1>
<ul>
{% for user in user %}
<li>Numero de compte: {{ user.Compte }} taux de TVA: {{ user.TauxTva }}
{{ user.plancomptable.intitule }}
</li>
{% endfor %}
</ul>
Cordialement
Salut,
Tu nommes ton attribut relation pourquoi pas planComptable puisque c'est ce qu'il est?
Fait un {{dump($user)} pour voir ce que ça contient dans ta vue
Tu as un soucis de nommage dans ton twig
for user in user