Update: Improved validation in CakePHP for version 1.x
I recently started a new project in CakePHP and thought it time to use version 1. But it seems the way that the validator code works has changed, so here is the updated code:
The following goes in app_model.php
Updated validator code
-
{
-
$data = $this->data;
-
}
-
-
if (!$this->beforeValidate()) {
-
return false;
-
}
-
-
return true;
-
}
-
-
-
$data = $data;
-
$data = $this->data;
-
}
-
-
$data = $data[$this->name];
-
}
-
-
foreach($this->validate as $field_name => $validators) {
-
foreach($validators as $validator) {
-
$errors[$field_name] = $validator[‘message’];
-
}
-
}
-
}
-
$this->validationErrors = $errors;
-
return $errors;
-
}
The validation helper method (See my previous post) looks like this:
Leave a comment