how should I implement validation on my non
Doctrine entities have validation metadata specified on their member fields independently of forms. Symfony2's form system somehow uses the validators provided by the entity.
How does that work? What ties it all together?
I have a non-doctrine model which I would like to validate without forms, but when I use forms they should use that validation information and display it correctly. So I need to:
Not sure if it handles your situation (as no code for a non-doctrine entity is provided), but you can use symfony validation constraints on values and arrays of values:
Validation
As an example of validating a couple of date values in array:
private function isInvalid($data)
{
$response = array();
$constraint = new Collection(array(
'from'=>new Date(),
'to'=>new Date(),
));
$validationList = $this->get('validator')->validateValue($data, $constraint);
if(count($validationList)>0) {
foreach($validationList as $err) {
array_push($data,array(
'field'=>$err->getPropertyPath(),
'message'=>$err->getMessage(),
));
}
return $response;
}
return false;
}
链接地址: http://www.djcxy.com/p/63146.html
上一篇: symfony2如何上传没有教义的文件?
下一篇: 我应该如何对我的非实施进行验证