1 回答

TA貢獻1936條經驗 獲得超7個贊
還需要一些其他的改變。
在我的客戶實體中,我必須更改:
? ? public function addEmployeSpy(EmployeSpie $employeSpy): self
? ? {
? ? ? ? if (!$this->employeSpies->contains($employeSpy)) {
? ? ? ? ? ? $this->employeSpies[] = $employeSpy;
? ? ? ? ? ? $employeSpy->addClientEmploye($this);
? ? ? ? }
? ? ? ? return $this;
? ? }
到 :
? ? public function addEmployeSpy(EmployeSpie $employeSpy): self
? ? {
? ? ? ? if (!$this->employeSpies->contains($employeSpy)) {
? ? ? ? ? ? $this->employeSpies[] = $employeSpy;
? ? ? ? ? ? $employeSpy->addClient($this);
? ? ? ? }
? ? ? ? return $this;
? ? }
刪除也是同樣的事情。
public function removeEmployeSpy(EmployeSpie $employeSpy): self
? ? {
? ? ? ? if ($this->employeSpies->contains($employeSpy)) {
? ? ? ? ? ? $this->employeSpies->removeElement($employeSpy);
? ? ? ? ? ? $employeSpy->removeClientEmploye($this);
? ? ? ? }
? ? ? ? return $this;
? ? }
到 :
public function removeEmployeSpy(EmployeSpie $employeSpy): self
? ? {
? ? ? ? if ($this->employeSpies->contains($employeSpy)) {
? ? ? ? ? ? $this->employeSpies->removeElement($employeSpy);
? ? ? ? ? ? $employeSpy->removeClient($this);
? ? ? ? }
? ? ? ? return $this;
? ? }
但在我的 ClientType 進行其他更改之后:
? ? ? ? ? ? ->add('employeSpies', EntityType::class, array(
? ? ? ? ? ? ? ? 'class' => EmployeSpie::class ,
? ? ? ? ? ? ? ? 'by_reference' => false,
? ? ? ? ? ? ? ? 'label'? ? ?=> 'Sélectionnez les employés rattachés à ce client',
? ? ? ? ? ? ? ? 'expanded'? => false,
? ? ? ? ? ? ? ? 'multiple'? => true,
? ? ? ? ? ? ))
我需要添加'by_reference' => false,才能使其正常工作。
因此,Symfony 不會嘗試查找“setClient”方法,而是查找addClient方法
希望它可以幫助以后其他人:)
- 1 回答
- 0 關注
- 132 瀏覽
添加回答
舉報