Q:

Cakephp 2 validation message on beforesave model callback

I am using CakePhp 2.5 and in a beforeSave model Callback i do return false if some information (MyIndex) is not provided.
How can i display the error message ?
I try :
$this->validationRuleErrors = 'You need to choose MyIndex'; 

But did not see any error message.
if( in_array( 'MyIndex', array_keys( $this->data) ) == FALSE )
{
            $this->validationRuleErrors = 'You need to choose MyIndex';
            debug($this->validationErrors);
            return false;
}

A:

The validationErrors property set in your beforeSave can be accessed from your controller.
Example controller:
try {
    $this->Model->save($data);
    if (!empty($this->Model->validationErrors)) {
        // just echo $this->Model->validationErrors if you don't want to use an exception
        throw new Exception($this->Model->validationErrors);
    }
} catch (Exception $e) {
    $this->data = [
        'success' => false,
        'message' => $e->getMessage()
    ]
}

