Changeset [fd649fceb806536326aa33898ddf179a9f4e5fc9] by Andrew Ho
July 5th, 2009 @ 11:46 PM
Abstracted code for custom validation rules
Essentially, the problem is that if you want to write functions for custom validation rules like isValidPID() that can also be used in other contexts to validate PIDs, you end up having to write two functions. The first, isValidPID($pid) takes a putative PID as the argument. The second, isValidPIDRule($data) takes $data as an argument so that you can use it as a rule:
'rule' => 'isValidPIDRule'
because this doesn't pass the value to be checked, it passes $data. Thus, isValidPIDRule looks like this:
function isValidPIDRule($data) {
// Extract $pid
$pid = array_values($data);
$pid[0] = $pid;
// Return validation result
return $this->isValidPID($pid);
}
As this ends up generating lots of wrapper functions, the neater way to this is to use customValidationFunction, which I've just written. What you do is:
'rule' => array('customValidationFunction', 'foo')
which returns the result of:
foo($value)
Parameters can be added to:
'rule' => array('customValidationFunction', 'foo', 'bar', 'foobar')
returns the result of:
foo($value, 'bar', 'foobar')
Committed by Andrew Ho
- M www/app/app_model.php
- M www/app/models/patient.php
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
A basic HIV Electronic Medical Record (EMR) system using CakePHP.