Parameter for Model::validates() is now deprecated
Since changeset 4260 the following usage of Model::validates(), used to validate a model without saving it, is deprecated and causes a warning:
if ($this->User->validates($this->data)) { // do something }
It looks now:
$this->User->data = $this->data; // or $this->data['User'];
if ($this->User->validates()) { // do something }
At the moment this change affects only those who use the Cake 1.2 branch from the repository.




The world is changing: I feel it in the water, I feel it in the earth, and I smell it in the air.
The change was made because it conflicts with handling validation in the callbacks. If you want to validate data without saving it, the easiest way to go about it is this:
if ($this->User->create($this->data) && $this->User->validates()) {
// Oh happy day
}
@nate: Thanks for the tip, your solution is more elegant.
off topic:
IBM’s Cake Series Part 4 is up:
http://www-128.ibm.com/developerworks/edu/os-dw-os-php-cake4.html
I also noticed these methods: controller->validateErrors and controller->validate. As I never needed them I was wondering if they can be useful in some circumstances anyway…?
@Tim: I don’t know what the use case is for those methods. I don’t use them. validateErrors() may be useful if you want to validate multiple models.