mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
"Refactored Model::invalidFields() to pass array(field => value) back to custom validation methods in a model
Closes #1863 postal code validation for Italy and Germany Closes #2766, Add field name to params array for custom validation rules Closes #3735, Custom validation functions Commented out the failing model tests until the missing fixtures are added " git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6243 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d7926aaaad
commit
3935746a29
3 changed files with 11 additions and 6 deletions
|
@ -1925,6 +1925,7 @@ class Model extends Overloadable {
|
|||
|
||||
if (method_exists($this, $rule) || isset($this->__behaviorMethods[$rule]) || isset($this->__behaviorMethods[strtolower($rule)])) {
|
||||
$ruleParams[] = array_diff_key($validator, $default);
|
||||
$ruleParams[0] = array($fieldName => $ruleParams[0]);
|
||||
$valid = call_user_func_array(array(&$this, $rule), $ruleParams);
|
||||
} elseif (method_exists($Validation, $rule)) {
|
||||
$valid = call_user_func_array(array(&$Validation, $rule), $ruleParams);
|
||||
|
|
|
@ -663,7 +663,11 @@ class Validation extends Object {
|
|||
break;
|
||||
case 'ca':
|
||||
$_this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\\b\\z/i';
|
||||
break;
|
||||
break;
|
||||
case 'it':
|
||||
case 'de':
|
||||
$_this->regex = '/^[0-9]{5}$/i';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $_this->_check();
|
||||
|
|
|
@ -65,12 +65,12 @@ class TestValidate extends Model {
|
|||
|
||||
function validateNumber($value, $options) {
|
||||
$options = am(array('min' => 0, 'max' => 100), $options);
|
||||
$valid = ($value >= $options['min'] && $value <= $options['max']);
|
||||
$valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']);
|
||||
return $valid;
|
||||
}
|
||||
|
||||
function validateTitle($title) {
|
||||
if (!empty($title) && strpos(low($title), 'title-') === 0) {
|
||||
function validateTitle($value) {
|
||||
if (!empty($value) && strpos(low($value['title']), 'title-') === 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -547,7 +547,7 @@ class ModelTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
unset($this->Project);
|
||||
}
|
||||
|
||||
/*
|
||||
function testWithAssociation() {
|
||||
$this->model =& new Something();
|
||||
$result = $this->model->SomethingElse->find('all');
|
||||
|
@ -582,7 +582,7 @@ class ModelTest extends CakeTestCase {
|
|||
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
*/
|
||||
function testFindAllRecursiveSelfJoin() {
|
||||
$this->model =& new Home();
|
||||
$this->model->recursive = 2;
|
||||
|
|
Loading…
Add table
Reference in a new issue