views:

98

answers:

2

Hi, I am trying to validate my model, I am using CakePHP 1.2.3.8166 and mysql 5

I have my model definied as it:

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 have 2 fields, maxfield and minfield, I need to validate maxfield always >= minfield but I can't figure out how to check minfield value! can someone help me please!

sorry my bad english, I speak spanish :)

Best regards

A: 

You can access the value of "minfield" with $this->data['Actividad']['minfield']

dhofstet
thanks, I was trying with this["minifield"]. thanks
Jorge Mota
A: 

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:

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.

zam3858
Oh Thanks, I put it in a array, because some example put it as it, (passing parameters I guess)
Jorge Mota