I have validation problem. I want to validate my model's property.
Here is the custom constraint I wrote:
#validation.yml
MyModel:
properties:
property_to_validate:
- MyConstraint: ~
#MyConstraint.php
class MyConstraint extends Constraint {
public $message = 'My message';
}
#MyConstraintValidator.php
class MyConstraintValidator extends ConstraintValidator {
public function isValid($value, Constraint $constraint) {
...
}
}
but
public function isValid($value, Constraint $constraint) {
//here
}
I have only $value. I need more properties from my model here, to
check if property under validation is correct
Ok. I can do this that way:
#validation.yml
MyModel:
constraints:
- MyConstraint: ~
#MyConstraint.php
class MyConstraint extends Constraint {
public $message = 'My message';
public function getTargets() {
return Constraint::CLASS_CONSTRAINT;
}
}
#MyConstraintValidator.php
class MyConstraintValidator extends ConstraintValidator {
public function isValid($object, Constraint $constraint) {
//here i have $object with all his properties
}
}
but then errors will not indicate the right property but the whole
model. It is not right in my case because e.g. errorr messages will be
displayed in wrong places in the form
Can you help me?
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en