Skip to content

Commit

Permalink
multiple invalid() call will collect multiple messages. validation er…
Browse files Browse the repository at this point in the history
…ror message is now localizable.
  • Loading branch information
basuke authored and Yosuke Basuke Suzuki committed Sep 7, 2011
1 parent 07b6523 commit e45cc81
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cake/libs/model/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ class Model extends Object {
*/
public $validationErrors = array();


/**
* Name of the validation string domain to use when translating validation errors.
*
* @var string
*/
public $validationDomain = null;

/**
* Database table prefix for tables in model.
*
Expand Down Expand Up @@ -2691,6 +2699,10 @@ public function invalidFields($options = array()) {
}
$validator = array_merge($default, $validator);

$validationDomain = $this->validationDomain;
if (empty($validationDomain)) {
$validationDomain = 'default';
}
if (isset($validator['message'])) {
$message = $validator['message'];
} else {
Expand All @@ -2710,7 +2722,7 @@ public function invalidFields($options = array()) {
);

if ($required) {
$this->invalidate($fieldName, $message);
$this->invalidate($fieldName, __d($validationDomain, $message));
if ($validator['last']) {
break;
}
Expand Down Expand Up @@ -2754,8 +2766,15 @@ public function invalidFields($options = array()) {
} elseif (is_numeric($index) && count($ruleSet) > 1) {
$validator['message'] = $index + 1;
} else {
$validator['message'] = $message;
$validator['message'] = __d($validationDomain, $message);
}
} elseif (is_array($validator['message'])) {
if (count($validator['message']) > 1) {
$args = array_slice($validator['message'], 1);
} else {
$args = $validator['rule'];
}
$validator['message'] = __d($validationDomain, $validator['message'][0], $args);
}
$this->invalidate($fieldName, $validator['message']);

Expand Down Expand Up @@ -2820,7 +2839,7 @@ public function invalidate($field, $value = true) {
if (!is_array($this->validationErrors)) {
$this->validationErrors = array();
}
$this->validationErrors[$field] = $value;
$this->validationErrors[$field] []= $value;
}

/**
Expand Down

0 comments on commit e45cc81

Please sign in to comment.