/** * Validates the model. * * @return boolean True if passed validators otherwise false */ private function _validate() { require_once 'Validations.php'; $validator = new Validations($this); $validationOn = 'ValidationOn' . ($this->isNewRecord() ? 'Create' : 'Update'); foreach (array('beforeValidation', "before{$validationOn}") as $callback) { if (!$this->invokeCallback($callback, false)) { return false; } } // need to store reference b4 validating so that custom validators have access to add errors $this->errors = $validator->getRecord(); $validator->validate(); foreach (array('afterValidation', "after{$validationOn}") as $callback) { $this->invokeCallback($callback, false); } if (!$this->errors->isEmpty()) { return false; } return true; }