Reputation: 2165
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;
}
Upvotes: 0
Views: 98
Reputation: 1656
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()
]
}
Upvotes: 1