我有下面的驗證約束的RegistrationFormType:Symfony2中:UniqueValidator爲形式
public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(),
new Email(array('message' => 'Ungültige E-Mail Adresse')),
),
'username' => new Unique(),
'code' => new MaxLength(array('limit'=>20)),
'plainPassword' => new MaxLength(array('limit'=>20)),
));
return array(
'csrf_protection' => false,
'validation_constraint' => $collectionConstraint,
);
}
爲了保證唯一性我創建一個唯一的類(延伸Contraint)和UniqueValidator(延伸ConstraintValidator)像這裏所描述:http://www.michelsalib.com/2011/04/create-your-own-constraint-validator-in-symfony2-a-doctrine-unique-validator/
的問題是,我得到提交表單以下錯誤:
Catchable Fatal Error: Argument 1 passed to ...\Validation\Constraint\UniqueValidator::__construct() must be an instance of Doctrine\ORM\EntityManager, none given
這似乎s表示了EntityManager沒有注入ConstraintValidator,我在config.yml創建服務定義,但:
services:
eventiply.validator.unique:
class: Ajado\EventHubBundle\Validation\UniqueValidator
arguments:
entityManager: "@doctrine.orm.entity_manager"
tags:
- { name: validator.constraint_validator, alias: validator.unique }
任何想法如何,我可以在這裏進步?
我有一個類似的[問題](http://stackoverflow.com/questions/8403440)。我從來沒有解決它。 – gilden 2012-01-13 20:58:37