Symfony Validators not loading?



我有以下作曲家文件:

{
  "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 AppModels;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorValidation;
use SymfonyComponentValidatorConstraints as Assert;
/**
 * @ORMEntity
 * @ORMTable(name="users")
 */
class User {
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue
     */
    protected $id;
    /**
     * @ORMColumn(type="string", length=32, nullable=false)
     */
    protected $firstName;
    /**
     * @ORMColumn(type="string", length=32, nullable=false)
     */
    protected $lastName;
    /**
     * @ORMColumn(type="string", length=100, unique=true, nullable=false)
     */
    protected $userName;
    /**
     * @ORMColumn(type="string", length=100, unique=true, nullable=false)
     * @AssertEmail
     */
    protected $email;
    /**
     * @ORMColumn(type="string", length=500, nullable=false)
     */
    protected $password;
    ...
}

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

  [DoctrineCommonAnnotationsAnnotationException]
  [Semantical Error] The annotation "@SymfonyComponentValidatorConstraintsEmail" in property AppModelsUser::$email does not exist, or could not be auto-loaded.

symfony的文档没有说明如何正确设置它,除了他们的github页面和他们的实际文档状态,几乎相同。

那么为什么我会收到此错误?我看了看,该类确实存在于已安装的验证器列表下......

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

DoctrineCommonAnnotationsAnnotationRegistry::registerLoader(array($loader, 'loadClass'));

链接到可能有用的信息。

相关内容

  • 没有找到相关文章

最新更新