我是Symfony的新手,我用它制作了一个网络应用程序,用户与ManyToMany有一个实体“使命”。它不起作用,因为我收到了错误
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
}
如何解决这个问题?谢谢
答案 0 :(得分:0)
要么你有错字:
getMission
而不是:
getMissions
或者您肯定没有在Mission实体中声明该方法,您调用方法的类也不在列表中。确保它继承自User。