Just to conclude this and to answer my own questions: The annotations n the entity class overwrite the "default message" of the constraint class. That's all the magic.
Hope it helps, Christian On Jan 20, 5:47 pm, cestcri <[email protected]> wrote: > By the way, > > can anybody explain how error messages are ideally set for custom > validators? > > 1. They can be "annotated" in the entity class, e.g. > > * @myValidation:Location(message="Provide a valid location!") > > 2. They are stated in the contraint class, e.g. > > class Location extends \Symfony\Component\Validator\Constraint > { > public $message = 'The location is not valid.'; > > } > > Which one is the correct spot to define the error message? And even > more important: why is the error message empty on failure of the > custom validator? > > Best regards, > Christian > > On Jan 20, 5:06 pm,cestcri<[email protected]> wrote: > > > Thanks Stof, I just found it... but it is good to know that I would > > have solved the issue anyway thanks to your eagle eyes ;) > > > Best regards, > > Christian > > > On Jan 20, 4:41 pm, stof <[email protected]> wrote: > > > > On Thu, 20 Jan 2011 07:33:42 -0800 (PST),cestcri<[email protected]> > > > wrote: > > > > > Hi Bernhard, > > > > > thanks for your quick reply. Here is what I have: > > > > > The validation setup in the entity class > > > > > /** > > > > * @var text $locationName > > > > * @myvalidation:Location(property="locationName", > > > > message="Geocoding of location failed!") > > > > */ > > > > private $locationName; > > > > > The setup in config.yml > > > > > app.config: > > > > validation: > > > > enabled: true > > > > annotations: > > > > namespaces: > > > > myvalidation: Application\RsBundle\Component > > > > \Validator\Constraints\ > > > > > The constraint class: > > > > > <?php > > > > > namespace Symfony\Component\Validator\Constraints; > > > > > class Location extends \Symfony\Component\Validator\Constraint > > > > { > > > > public $message = 'The location is not valid.'; > > > > } > > > > > The validator: > > > > > <?php > > > > > namespace Application\RsBundle\Component\Validator\Constraints; > > > > > use Symfony\Component\Validator\Constraint; > > > > use Symfony\Component\Validator\ConstraintValidator; > > > > > class LocationValidator extends ConstraintValidator > > > > { > > > > public function isValid($object, Constraint $constraint) > > > > { > > > > throw new \RuntimeException('This is it.'); > > > > } > > > > } > > > > > isValid() is never called, i.e. the exception is not thrown. > > > > > Happy to get some advice :) > > > > > Thanks in advance, > > > > Christian > > > > The namespace of the constraint class is false. So this constraint cannot > > > be found and then call the associated validator (which will not be found > > > in > > > the current case as it is in a different namespace) > > > > Regards > > > > -- > > > Christophe | Stof > > -- 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 users" 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-users?hl=en
