Doctrine orm 使用学说2的统一性

Doctrine orm 使用学说2的统一性,doctrine-orm,entity,zend-framework2,unique-index,Doctrine Orm,Entity,Zend Framework2,Unique Index,我正在使用Zend Framework 2,并创建了一个用户实体。现在我正在尝试使用户名字段唯一。然而,下面的错误即将出现 [Semantical Error] The annotation "@UniqueEntity" in class User\Entity\User was never imported. Did you maybe forget to add a "use" statement for this annotation? 我已添加此代码以进行唯一性检查 @UniqueE

我正在使用Zend Framework 2,并创建了一个用户实体。现在我正在尝试使用户名字段唯一。然而,下面的错误即将出现

[Semantical Error] The annotation "@UniqueEntity" in class User\Entity\User was never imported. Did you maybe forget to add a "use" statement for this annotation?
我已添加此代码以进行唯一性检查

@UniqueEntity("email")
我可以看出这是Symfony中使用的一种方法。如何将其用于Zend Framework 2?

这就是我正在使用的实体

<?php

namespace User\Entity;

use Doctrine\ORM\Mapping as ORM,
    Zend\Form\Annotation;

/**
 * A user entity.
 *
 * @ORM\Entity
 * @ORM\Table(name="users")
 * @UniqueEntity("email")

 * @property int $id
 * @property string $username
 * @property string $email
 * @property string $password
 * 
 * @Annotation\Name("User")
 */
class User {

  /**
   * @ORM\Id
   * @ORM\Column(type="integer");
   * @ORM\GeneratedValue(strategy="AUTO")
   * 
   * @Annotation\Required(false)
   */
  protected $id;

  /**
   * @ORM\Column(type="string")
   * 
   * @Annotation\Attributes({"type":"text"})
   * @Annotation\Options({"label":"Username:"})
   * @Annotation\Filter({"name":"StringTrim"})
   * @Annotation\Filter({"name":"StripTags"})
   */
  protected $username;

  /**
   * @ORM\Column(type="string")
   * 
   * @Annotation\Attributes({"type":"text" })
   * @Annotation\Options({"label":"Email:"})
   * @Annotation\Filter({"name":"StringTrim"})
   * @Annotation\Filter({"name":"StripTags"})
   */
  protected $email;

  /**
   * @ORM\Column(type="string")
   * 
   * @Annotation\Attributes({"type":"text" })
   * @Annotation\Options({"label":"Password:"})
   * @Annotation\Filter({"name":"StringTrim"})
   * @Annotation\Filter({"name":"StripTags"})
   */
  protected $password;    

  public function __get($property) {
    return $this->$property;
  }

  /**
   * Magic setter to save protected properties.
   *
   * @param string $property
   * @param mixed $value
   */
  public function __set($property, $value) {
    $this->$property = $value;
  }

  public function getArrayCopy() {
    return array(
        'username' => $this->username,
        'email' => $this->email,
        'surname' => $this->surname,
        'first_name' => $this->first_name,
        'company' => $this->company,
        'postcode' => $this->postcode,
    );
  }

  public function populate($data) {
    $this->username = isset($data['username']) ? $data['username'] : $this->username;
  }

  public function setDate($property, $value){
    $this->$property = new \DateTime($value);
  }

}

@UniqueEntity
是symfony验证组件的一个特定扩展(在这里作为注释编写)。您要查找的可能是您可以在
doctriemodule
中找到的验证器:

对它作为注释的支持尚未内置。

2秒谷歌:(