Answer the question
In order to leave comments, you need to log in
How to properly cure this error: could not be converted to string?
Hello everyone,
I generated ManyToMany and created CRUD, but for some reason it gives an error:
Catchable Fatal Error: Object of class App\Entity\Account could not be converted to string
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\AccountRepository")
*/
class Account
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $benutzer;
public function getId(): ?int
{
return $this->id;
}
public function getBenutzer(): ?string
{
return $this->benutzer;
}
public function setBenutzer(string $benutzer): self
{
$this->benutzer = $benutzer;
return $this;
}
public function __toString(){
// to show the name of the Category in the select
return $this->benutzer;
}
}
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\MenschenRepository")
*/
class Menschen
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Account")
*/
private $account;
/**
* @ORM\Column(type="string", length=255)
*/
private $vorname;
public function __construct()
{
$this->account = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Account[]
*/
public function getAccount(): Collection
{
return $this->account;
}
public function addAccount(Account $account): self
{
if (!$this->account->contains($account)) {
$this->account[] = $account;
}
return $this;
}
public function removeAccount(Account $account): self
{
if ($this->account->contains($account)) {
$this->account->removeElement($account);
}
return $this;
}
public function getVorname(): ?string
{
return $this->vorname;
}
public function setVorname(string $vorname): self
{
$this->vorname = $vorname;
return $this;
}
}
public function __toString(){
return $this->benutzer;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question