http://book.cakephp.org/2.0/en/models/data-validation/validating-data-from-the-controller.html

First, set the data to the model:
$this->ModelName->set($this->request->data);

Then, to check if the data validates, use the validates method of the model, 
which will return true if it validates and false if it doesn’t:
if ($this->ModelName->validates()) {
    // it validated logic
} else {
    // didn’t validate logic
    $errors = $this->ModelName->validationErrors;
}

Andras

> On Feb 21, 2015, at 12:50 AM, giuseppe giorgio <[email protected]> wrote:
> 
> Hi there, i've start to learn cake php yesterday, and i have a question. I've 
> declared validation array inside my model class like:
> 
>     
> public $validate = array(
>     'username' => array(
>         'alphaNumeric' => array(
>             'rule' => 'alphaNumeric',
>             'required' => true,
>             'message' => 'username required'
>          ),
>          'unique' => array(
>             'rule' => 'isUnique',
>             'required' => 'create',
>             'message' => 'Username already used'
>          )
>         ));
> 
> 
> When i add a new record to my database by using add(), everithing works fine, 
> and alert message are showed automatically. How can i intercept this error 
> message firing inside add() controller function? because if a message is 
> fired, i would perform an action (and not simply show message)
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to