9
我是Symfony2的新手。雖然這個問題與Doctrine和FOSUserBundle有關。Symfony2 - Doctrine和FOSUserBundle - 錯誤註釋
我有以下User.php實體創建基於FOSUserBundle和自引用多對多。
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@ManyToMany" in property Pan100\MoodLog
Bundle\Entity\User::$hasAccessTo was never imported. Did you maybe forget
to add a "use" statement for this annotation?
什麼是錯在這裏:
<?php
namespace Pan100\MoodLogBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ManyToMany(targetEntity="User", mappedBy="hasAccessToMe")
**/
protected $hasAccessTo;
/**
* @ManyToMany(targetEntity="User", inversedBy="hasAccessTo")
* @JoinTable(name="access",
* joinColumns={@JoinColumn(name="id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="accessor_id", referencedColumnName="id")}
* )
**/
private $hasAccessToMe;
public function __construct()
{
parent::__construct();
$this->hasAccessTo = new \Doctrine\Common\Collections\ArrayCollection();
$this->hasAccessToMe = new \Doctrine\Common\Collections\ArrayCollection();
}
}
嘗試更新緩存或下降時,給了我下面的錯誤?什麼是「使用聲明」?
成功!因爲我使用它作爲ORM,所以我必須將ORM \放在所有註釋之前。 – Piddien 2013-02-25 14:13:44