/** * Validates the model. * * @return boolean True if passed validators otherwise false */ private function _validate() { $validator = new Validations($this); $validation_on = 'validation_on_' . ($this->is_new_record() ? 'create' : 'update'); foreach (array('before_validation', "before_{$validation_on}") as $callback) { if (method_exists($this, $callback) && !call_user_func(array($this, $callback))) { return false; } } // need to store reference b4 validating so that custom validators have access to add errors $this->errors = $validator->get_record(); $validator->validate(); foreach (array('after_validation', "after_{$validation_on}") as $callback) { if (method_exists($this, $callback)) { call_user_func(array($this, $callback)); } } if (!$this->errors->is_empty()) { return false; } return true; }
/** * Validates the model. * * @return boolean True if passed validators otherwise false */ private function _validate() { require_once 'Validations.php'; $validator = new Validations($this); $validation_on = 'validation_on_' . ($this->is_new_record() ? 'create' : 'update'); foreach (array('before_validation', "before_{$validation_on}") as $callback) { if (!$this->invoke_callback($callback, false)) { return false; } } // need to store reference b4 validating so that custom validators have access to add errors $this->errors = $validator->get_record(); $validator->validate(); foreach (array('after_validation', "after_{$validation_on}") as $callback) { $this->invoke_callback($callback, false); } if (!$this->errors->is_empty()) { return false; } return true; }