Hi crickt,

thanks for your answer, it give me an idea about what I could do.

If someone else is looking for how to set a custom message for default cake 
validators in all models of the project, take a look at my code.

class AppModel extends Model {
    
    private $customValidationMessages = array(
        'notempty' => 'This field can not be empty.',
        'email'   => 'This is not a valid e-mail address.'
    );
    
    public function beforeValidate() {
        foreach ($this->validate as $attributeToValidate => $validations) { 
  
            foreach ($validations as $rule => $validation) {
                if 
(empty($this->validate[$attributeToValidate][$rule]['message']) && 
!empty($this->customValidationMessages[$rule])) {
                    $this->validate[$attributeToValidate][$rule]['message'] 
= $this->customValidationMessages[$rule];
                }
            }
        }
    }
    
}

if there is some better way to do that, please, let me know.

Em terça-feira, 27 de novembro de 2012 11h33min09s UTC-2, vitor gomes 
escreveu:
>
> Hi,
>
> I'm starting two different projects using cake, but there are several 
> validations in my forms that will be the basically the same, like notempty 
> for exemple. I will use Bake to generate my CRUDs.
>
> What I need to know is if there is any option to set custom message errors 
> for those default validators and some how don't need to set it in every 
> single model in both projects. 
>
> There is some option to set custom messages for validators in some place 
> and it Cake display everytime I use this validator?
>
> Best regards,
> Vitor.
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to