In a cake model I have 6 fields that all have the same validation rules. Is there a way to assign this rule to all 6 fields without having to copy-paste the array?
E.g.
public $currency_validate = array(
'rule1'=>array(
'rule' => array('comparison', '>=', 0),
'message' => 'Must be between 0 and 1'
),
'rule2' => array(
'rule' => array('comparison', '<=', 1),
'message' => 'Must be between 0 and 1'
)
);
public $validate = array(
'usd' => $this->currency_validate,
'gbp' => $this->currency_validate,
'eur' => $this->currency_validate,
//etc
);
Does not work as one is not allowed to dynamical assign properties in a class.
__constructmethod in my model I get: Error: Call to a member function dispatchMethod() on a non-object - harryg