[英]Doctrine @Assert Annotation Validation not working
I have a document with the following field in Symfony / Mongo document definition: 我在Symfony / Mongo文档定义中具有以下字段的文档:
/**
* @MongoDB\String
* @Assert\NotEmpty
* @Assert\Regex(pattern="/([0-9]{4})/", message="Please use the YYYY format")
* @Type("string")
* Example "2014"
*/
protected $year;
However, whenever I create a new document and persist it to MongoDB, Doctrine doesn't enforce any Assert definitions at all... it allows just about any value to be saved for this field. 但是,每当我创建一个新文档并将其保存到MongoDB时,Doctrine根本不会执行任何Assert定义...它几乎可以为该字段保存任何值。
Any ideas? 有任何想法吗?
Thanks @Maerlyn. 谢谢@Maerlyn。 Yes, apparently, I need to do proper validation before I persist the document eg 是的,显然,我在保存文档之前需要进行适当的验证,例如
$validator = $this->get('validator');
$violations = $validator->validate($myObj);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.