Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduce an addError method to model

  • Loading branch information...
commit 36fd84536bc588a9695713f16fd61cc5ad0c7ef1 1 parent 055a688
Andy Pearson authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/core/data/model.php
9 lib/core/data/model.php
View
@@ -240,8 +240,7 @@ function valid()
$invalid = $this->{"validate".Inflector::camelize($rule['with'])}($attribute, $value, $options);
if ($invalid) {
- if (!isset($this->_errors[$attribute])) $this->_errors[$attribute] = array();
- $this->_errors[$attribute][] = (isset($rule['message'])) ? $rule['message'] : 'There is an error on this field.';
+ $this->addError($attribute, isset($rule['message']) ? $rule['message'] : null);
}
}
}
@@ -249,6 +248,12 @@ function valid()
return empty($this->_errors);
}
+ function addError($attribute, $message = null)
+ {
+ if (!isset($this->_errors[$attribute])) $this->_errors[$attribute] = array();
+ $this->_errors[$attribute][] = $message ? $message : 'There is an error on this field.';
+ }
+
function errors($attribute)
{
return (isset($this->_errors[$attribute])) ? $this->_errors[$attribute] : array();
Please sign in to comment.
Something went wrong with that request. Please try again.