Search

Friends

Atomspheric CO2 (PPM)

Archives

Blather

Uptime verified by Wormly.com

21 December 2011

Symfony2 invalid type messages

Symfony2 will automatically add validation to entity fields ensuring that values match the database type. For instance, If you try to set an alpha character on a DECIMAL column you will get "This value is not valid" along with other constraint violations. If you manually add a Type Constraint you'll end up with a largely duplicate assertion. However, if you want to set the message on the default constraint, you can't do it in the entity itself. You have to do it in the form class.

$builder->add('amount', 'money', array(
  'label' => 'Default Price', 
  'invalid_message' => 'Price must be a number'
));

I couldn't find that documented anywhere, but it works.

Comments

No comments yet.

Leave a comment

Markdown

0.176 seconds