An exception has been thrown during the rendering of a template ("Notice: Object of class Proxies_CG_\App\Entity\Professional could not be converted to int").
I am developing in Symfony 4. This is my first time when I work with 2 entities linked together.
My twig template:
{% for contact in contacts %}
{% if contact.professional == professional.id %}
<tr>
<th>{{ contact.giftCheck }}</th>
</tr>
{% endif %}
{% endfor %}
My Entities: Professional(what is related to contact)
/**
* @ORM\OneToMany(targetEntity=PlaceComment::class, mappedBy="professional", orphanRemoval=true)
*/
private $placeComments;
public function __construct()
{
//some more collections ...
$this->contacts = new ArrayCollection();
}
/**
* @return Collection|Contact[]
*/
public function getContacts(): Collection
{
return $this->contacts;
}
public function addContact(Contact $contact): self
{
if (!$this->contacts->contains($contact)) {
$this->contacts[] = $contact;
$contact->setProfessional($this);
}
return $this;
}
public function removeContact(Contact $contact): self
{
if ($this->contacts->removeElement($contact)) {
// set the owning side to null (unless already changed)
if ($contact->getProfessional() === $this) {
$contact->setProfessional(null);
}
}
return $this;
}
My Entities: Contact
/**
* @ORM\Entity(repositoryClass=ContactRepository::class)
*/
class Contact
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="datetime")
*/
private $date;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $confirmed;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $completed;
/**
* @ORM\ManyToOne(targetEntity=GiftCheck::class, inversedBy="contacts")
* @ORM\JoinColumn(nullable=false)
*/
private $giftCheck;
/**
* @ORM\ManyToOne(targetEntity=Professional::class, inversedBy="contacts")
* @ORM\JoinColumn(nullable=false)
*/
private $professional;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $confirmationDate;
function __construct($giftCheck, $professional)
{
$this->giftCheck = $giftCheck;
$this->professional = $professional;
$this->date = new DateTime('now', new DateTimeZone('Europe/Paris'));
}
public function getId(): ?int
{
return $this->id;
}
//a bunch of setters and getters
Just check for the contact.professional.id to be equal to the professional.id, that all:
{% for contact in contacts %}
{% if contact.professional.id == professional.id %}
<tr>
<th>{{ contact.giftCheck }}</th>
</tr>
{% endif %}
{% endfor %}