类xx中的注释@Doctrine\ORM\Mapping不存在或无法加载。

8

在执行php app/console doctrine:generate:entities etBundle:Users时,我得到了以下错误消息:

[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Doctrine\ORM\Mapping" in class Ampisoft\Bundle\etrackBundle\Entity\Users does not exist, or could not be auto-loaded.

我的实体类如下:

namespace Ampisoft\Bundle\etrackBundle\Entity;


 use Doctrine\ORM\Mapping as ORM;

 /**
 * @ORM/Entity
 * @ORM/Table(name="users")
 */
class Users
{
/**
 * @ORM/Column(type="integer")
 * @ORM/ID
 * @ORM/GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=25, unique=true)
 */
protected $username;

/**
 * @ORM\Column(type="string", length=64)
 */
protected $password;


/**
 * @ORM\Column(name="is_active", type="boolean")
 */
private $isActive;

/**
 * @ORM\Column(type="string", length=60, unique=true)
 */
protected $email;

/**
 * @ORM\Column(type="datetime")
 */
protected $lastLogged;
}

我在Stack Overflow上查看了相关问题的解决方案,但是这些方案都与属性有关,还有一些与Zend有关,但没有与Symfony2中实际的类声明有关的解决方案。

我使用Composer安装并更新了所有供应商软件包。

请问是否有人能够指点我正确的方向?

我对Symfony很新,请多多指教。


6
嗯,我认为你需要将正斜杠替换为反斜杠:@ORM/Entity 替换为 @ORM\Entity。不知道这是否有助于解决问题,但尝试一下不会有任何损失... ;) - Jovan Perovic
1个回答

25

如果您在注释名称中使用正斜杠(/)而不是反斜杠(\),则会出现此错误。也就是说,如果您这样做,将会发生错误:

/**
 * @ORM/Entity
 */

不是正确的方式:

/**
 * @ORM\Entity
 */

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接