Symfony Validators没有加载?

时间:2015-04-30 17:19:41

标签: php symfony doctrine-orm

我有以下作曲家文件:

{
  "require": {
    "doctrine/orm": "2.4.*",
    "doctrine/migrations": "1.0.*@dev",
    "symfony/validator": "2.8.*@dev",
    "slim/slim": "~2.6",
    "freya/freya-exception": "0.0.7",
    "freya/freya-loader": "0.2.2",
    "freya/freya-templates": "0.1.2",
    "freya/freya-factory": "0.0.8"
  },
  "autoload": {
    "psr-4": {"": ""}
  }
}

我创建了以下实体,或者我称之为模型:

namespace App\Models;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
class User {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=32, nullable=false)
     */
    protected $firstName;

    /**
     * @ORM\Column(type="string", length=32, nullable=false)
     */
    protected $lastName;

    /**
     * @ORM\Column(type="string", length=100, unique=true, nullable=false)
     */
    protected $userName;

    /**
     * @ORM\Column(type="string", length=100, unique=true, nullable=false)
     * @Assert\Email
     */
    protected $email;

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

    ...
}

现在当我运行"vendor/bin/doctrine" migrations:diff时出现错误:

  [Doctrine\Common\Annotations\AnnotationException]
  [Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\Email" in property App\Models\User::$email does not exist, or could not be auto-loaded.

除了github page及其实际文档状态之外,symfony的文档没有说明如何正确设置它的内容,几乎相同。

那我为什么会收到此错误?我看了,课程安装在验证器列表下面......

1 个答案:

答案 0 :(得分:2)

似乎你需要一点胶水才能让它与你的微框架引导一起工作:

\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

Link to information可能有用。