I am trying to validate my model, I am using CakePHP 1.2.3.8166 and mysql 5
我正在尝试验证我的模型,我正在使用CakePHP 1.2.3.8166和mysql 5
I have my model definied as it:
我的模型定义如下:
<?php
class Actividad extends AppModel {
var $name = 'Actividad';
var $validate = array('maxfield' => array(
'rule'=> array('chkValue'),
'message'=>'i2'
));
function chkValue($data){
return $data["maxfield"]>=$data["minfield"]
}
}
My table has 2 fields; maxfield
& minfield
. I need to validate maxfield
always >= minfield
but I can't figure out how to check minfield
value.
我的桌子有2个字段; maxfield&minfield。我需要验证maxfield always> = minfield但我无法弄清楚如何检查minfield值。
2 个解决方案
#1
You can access the value of "minfield" with $this->data['Actividad']['minfield']
您可以使用$ this-> data ['Actividad'] ['minfield']访问“minfield”的值
#2
you already have the validation for maxfield, you just need to do the same thing with the minfield. so your $validate should be like this:
你已经对maxfield进行了验证,你只需要对minfield做同样的事情。所以你的$ validate应该是这样的:
var $validate= array(
'maxfield' => array(
'rule'=> 'chkValue',
'message'=>'i2'
),
'minfield' => array(
'rule'=> 'chkValue',
'message'=>'i2'
)
);
And by the way. 'rule' => 'nameOfValidationFunction'. no need to put in array.
顺便说一下。 'rule'=>'nameOfValidationFunction'。无需放入数组。
#1
You can access the value of "minfield" with $this->data['Actividad']['minfield']
您可以使用$ this-> data ['Actividad'] ['minfield']访问“minfield”的值
#2
you already have the validation for maxfield, you just need to do the same thing with the minfield. so your $validate should be like this:
你已经对maxfield进行了验证,你只需要对minfield做同样的事情。所以你的$ validate应该是这样的:
var $validate= array(
'maxfield' => array(
'rule'=> 'chkValue',
'message'=>'i2'
),
'minfield' => array(
'rule'=> 'chkValue',
'message'=>'i2'
)
);
And by the way. 'rule' => 'nameOfValidationFunction'. no need to put in array.
顺便说一下。 'rule'=>'nameOfValidationFunction'。无需放入数组。