I have a weird issue with Doctrine. I have set up the following structure:
Hers is ProfilRadnogMjestasPoslov Entity class
/**
* @ORM\Entity(repositoryClass=ProfilRadnogMjestasPoslovRepository::class)
*/
class ProfilRadnogMjestasPoslov
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
/**
* Description of the applicable level of competence.
*
* @ORM\Column(type="string", length=1024, nullable=true)
*/
private $posloviRadnogMjesta;
public function getPosloviRadnogMjesta(): ?string
{
return $this->posloviRadnogMjesta;
}
public function setPosloviRadnogMjesta(?string $posloviRadnogMjesta): self
{
$this->posloviRadnogMjesta = $posloviRadnogMjesta;
return $this;
}
/**
* @ORM\ManyToOne(targetEntity=ProfilRadnogMjesta::class, inversedBy="profilRadnogMjestasPoslova")
* @ORM\JoinColumn(name="profil_radnog_mjesta_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $profilRadnogMjesta;
public function __construct()
{
}
public function getProfilRadnogMjesta(): ?ProfilRadnogMjesta
{
return $this->profilRadnogMjesta;
}
public function setProfilRadnogMjesta(?ProfilRadnogMjesta $profilRadnogMjesta): self
{
$this->profilRadnogMjesta = $profilRadnogMjesta;
return $this;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\WorkArea")
* @ORM\JoinColumn(name="podrucje_rada_id", referencedColumnName="id")
*/
private $workArea;
public function getWorkarea(): ?WorkArea
{
return $this->workArea;
}
public function setWorkarea(?WorkArea $WorkArea): self
{
$this->workArea = $WorkArea;
return $this;
}
/**
* @ORM\Column(type="integer")
*/
private $podrucje_rada_id;
public function getPodrucjeRadaId(): ?int
{
return $this->podrucje_rada_id;
}
public function setPodrucjeRadaId(?int $podrucje_rada_id): self
{
$this->podrucje_rada_id = $podrucje_rada_id;
return $this;
}
/**
* @ORM\Column(type="integer")
*/
private $slozenost_poslova_id;
public function getSlozenostPoslovaId(): ?int
{
return $this->slozenost_poslova_id;
}
public function setSlozenostPoslovaId(?int $slozenost_poslova_id): self
{
$this->slozenost_poslova_id = $slozenost_poslova_id;
return $this;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Job")
* @ORM\JoinColumn(name="slozenost_poslova_id", referencedColumnName="id")
*/
private $job;
public function getJob(): ?Job
{
return $this->job;
}
public function setJob(?Job $job): self
{
$this->job = $job;
return $this;
}`
ProfilRadnogMjesta Entity
/**
* @ORM\Entity()
*/
class ProfilRadnogMjesta
{
const EDIT_ROUTE = 'job_profile_edit';
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* Job title - (select from Radna mjesta).
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nazivRadnogMjesta;
/**
* Broj izvršitelja - Executor number.
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $brojIzvrsitelja;
/**
* Kategorija radnog mjesta - Job category - selecting from table.
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $kategorijaRadnogMjesta;
/**
* Pod kategorija - Sub Category - selecting from table.
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $podKategorija;
/**
* @ORM\OneToMany(targetEntity=ProfilRadnogMjestasUtility::class, mappedBy="profilRadnogMjesta", cascade={"persist","remove"})
*/
private $profilRadnogMjestasUtility;
/**
* @ORM\OneToMany(targetEntity=ProfilRadnogMjestasRukovodece::class, mappedBy="profilRadnogMjesta", cascade={"persist","remove"})
*/
private $profilRadnogMjestasRukovodece;
/**
* @ORM\OneToMany(targetEntity=ProfilRadnogMjestasKvalifikacije::class, mappedBy="profilRadnogMjesta", cascade={"persist","remove"})
*/
private $profilRadnogMjestasKvalifikacije;
/**
* @ORM\OneToMany(targetEntity=ProfilRadnogMjestasPoslov::class, mappedBy="profilRadnogMjesta", cascade={"persist","remove"})
*/
private $profilRadnogMjestasPoslov;
######## Constructor Starts ########
/**
* @param $id
*/
public function __construct()
{
$this->profilRadnogMjestasUtility = new ArrayCollection();
$this->profilRadnogMjestasRukovodece = new ArrayCollection();
$this->profilRadnogMjestasKvalifikacije = new ArrayCollection();
$this->profilRadnogMjestasPoslov = new ArrayCollection();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
* @return ProfilRadnogMjesta
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getNazivRadnogMjesta(): ?string
{
return $this->nazivRadnogMjesta;
}
/**
* @param string $nazivRadnogMjesta
* @return ProfilRadnogMjesta
*/
public function setNazivRadnogMjesta(string $nazivRadnogMjesta): ProfilRadnogMjesta
{
$this->nazivRadnogMjesta = $nazivRadnogMjesta;
return $this;
}
/**
* @return string
*/
public function getBrojIzvrsitelja(): ?string
{
return $this->brojIzvrsitelja;
}
/**
* @param string $brojIzvrsitelja
* @return ProfilRadnogMjesta
*/
public function setBrojIzvrsitelja(string $brojIzvrsitelja): ProfilRadnogMjesta
{
$this->brojIzvrsitelja = $brojIzvrsitelja;
return $this;
}
/**
* @return string
*/
public function getKategorijaRadnogMjesta(): ?string
{
return $this->kategorijaRadnogMjesta;
}
/**
* @param string $kategorijaRadnogMjesta
* @return ProfilRadnogMjesta
*/
public function setKategorijaRadnogMjesta(string $kategorijaRadnogMjesta): ProfilRadnogMjesta
{
$this->kategorijaRadnogMjesta = $kategorijaRadnogMjesta;
return $this;
}
/**
* @return string
*/
public function getPodKategorija(): ?string
{
return $this->podKategorija;
}
/**
* @return Collection|ProfilRadnogMjestasPoslov[]
*/
public function getProfilRadnogMjestasPoslov(): ?Collection
{
return $this->profilRadnogMjestasPoslov;
}
public function addProfilRadnogMjestasPoslov(ProfilRadnogMjestasPoslov $profilRadnogMjestasPoslov): self
{
if (!$this->profilRadnogMjestasPoslov || !$this->profilRadnogMjestasPoslov->contains($profilRadnogMjestasPoslov)) {
$this->profilRadnogMjestasPoslov[] = $profilRadnogMjestasPoslov;
$profilRadnogMjestasPoslov->setProfilRadnogMjesta($this);
}
return $this;
}
public function removeProfilRadnogMjestasPoslov(ProfilRadnogMjestasPoslov $profilRadnogMjestasPoslov): self
{
if ($this->profilRadnogMjestasPoslov->contains($profilRadnogMjestasPoslov)) {
$this->profilRadnogMjestasPoslov->removeElement($profilRadnogMjestasPoslov);
// set the owning side to null (unless already changed)
if ($profilRadnogMjestasPoslov->getProfilRadnogMjesta() === $this) {
$profilRadnogMjestasPoslov->setProfilRadnogMjesta(null);
}
}
return $this;
}
In my controller :
$id = $request->get('id');
$repository = $this->entityManager->getRepository(ProfilRadnogMjesta::class);
$profit = $repository->find($id);
$html = $this->twig->render('reports/profit-report.html.twig', [
'profit' => $profit,.....
In my Twig :
<td class="" width="46%">{{ profit.posloviRadnogMjesta }}</td>
So I get this error Neither the property "posloviRadnogMjesta" nor one of the methods "posloviRadnogMjesta()", "getposloviRadnogMjesta()"/"isposloviRadnogMjesta()"/"hasposloviRadnogMjesta()" or "__call()" exist and have public access in class "App\Entity\ProfilRadnogMjesta".
Does anybody know why this error occurs and how I can fix it? Is something wrong with my mapping?
Thanks for your help!
The code fetchs one object through the repository:
The Twig code will try to fetch
posloviRadnogMjesta:So it will try to call
getPosloviRadnogMjesta()andisposloviRadnogMjesta().But the method
getPosloviRadnogMjesta()only exists in the entityProfilRadnogMjestasPoslov.So you have to move the method
getPosloviRadnogMjesta()in the classProfilRadnogMjestaor call the repository for the other class: