0
我是Symfony的新成員,我用它製作了一個web應用程序,用戶與一個實體「Mission」有許多關係ManyToMany。這是行不通的,因爲我得到調用未定義的方法ArrayCollection
FatalErrorException: Error: Call to undefined method
Acme\ManagementBundle\Entity\UserGroundStation::getMission()
特getMission在MissionEntity定義,並要求在結構錯誤。我是否必須再次定義它?我不明白。
我的用戶是:
<?php
namespace Acme\ManagementBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="user")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"user_one" = "UserGroundStation", "user_two" = "UserOperator"})
* @ORM\MappedSuperclass()
*
*/
abstract class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="Acme\ManagementBundle\Entity\Mission", mappedBy="users")
*/
protected $missions;
public function __construct(){
parent::__construct();
$this -> missions = new ArrayCollection();
}
public function setMissions(Collection $missions){
$this -> missions = $missions;
return $this;
}
public function addMission($mission){
$this -> missions -> add($mission);
return $this;
}
public function getMissions(){
return $this -> missions;
}
}
和任務實體是:
/**
* @ORM\Entity
*/
class Mission {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @var integer
*/
protected $id;
/**
* @ORM\Column(type="string", length=60)
* @var String
*/
protected $name;
/**
* @ORM\Column(type="string", length=600)
* @var String
*/
protected $description;
/**
* @ORM\ManyToMany(targetEntity="Acme\ManagementBundle\Entity\User", inversedBy="users")
*/
protected $users;
public function __construct(){
$this -> users = new ArrayCollection();
}
public function setUsers(Collection $users){
$this -> users = $users;
return $this;
}
public function addUser($user){
$this -> users -> add($user);
return $this;
}
public function getUsers(){
return $this -> users;
}
//setters and getters for id, name and description
}
如何解決這個問題?謝謝
哦,謝謝你,這是錯字,我認爲這是正確的。但我不明白你答案的第二部分; 「用戶」方法在Mission實體中聲明,我應該做些什麼? –