Something fun about the RC1 release: SQL conditions are now put in the KEY of the conditions array rather then VALUE of the array. For example:
Old:
$conditions = array('Foo.bar' => '> 23');New:
$conditions = array('Foo.bar >' => 23);Follow a large project as it moves from a custom PHP framework to CakePHP.
$conditions = array('Foo.bar' => '> 23');$conditions = array('Foo.bar >' => 23);/**
* V.I.N.E. - Validate If Not Empty
* Validates a field against given validation rule if it's not empty
*
* @param array $data
* @param string $fieldName
* @param array $validationRule
* @return bool
*/
public function vine($data, $fieldName, $validationRule)
{
$valid = false;
if (!isset($fieldName) or !isset($validationRule)) {
return false;
}
if (empty($data[$fieldName])) {
return true;
}
$validator = $this->validate[$fieldName];
$Validation = new Validation();
$method = array_shift($validator['rule'][2]);
$params = am($data[$fieldName], array_values($validator['rule'][2]));
$valid = call_user_func_array(array(&$Validation, $method), $params);
if (!$valid) {
$this->invalidate($fieldName, $validator['message']);
}
unset($this->validate[$fieldName]);
return $valid;
}
// Example use
'tollFreePhone' => array('rule' => array('vine', 'tollFreePhone', array('between', 7, 255)),
'required' => false,
'message' => 'Toll-free phone must be between 7 and 255 characters.'),