3
* CFilterValidator class file.
5
* @author Qiang Xue <qiang.xue@gmail.com>
6
* @link http://www.yiiframework.com/
7
* @copyright Copyright © 2008-2011 Yii Software LLC
8
* @license http://www.yiiframework.com/license/
12
* CFilterValidator transforms the data being validated based on a filter.
14
* CFilterValidator is actually not a validator but a data processor.
15
* It invokes the specified filter method to process the attribute value
16
* and save the processed value back to the attribute. The filter method
17
* must follow the following signature:
19
* function foo($value) {...return $newValue; }
21
* Many PHP functions qualify this signature (e.g. trim).
23
* To specify the filter method, set {@link filter} property to be the function name.
25
* @author Qiang Xue <qiang.xue@gmail.com>
26
* @version $Id: CFilterValidator.php 2799 2011-01-01 19:31:13Z qiang.xue $
27
* @package system.validators
30
class CFilterValidator extends CValidator
33
* @var callback the filter method
38
* Validates the attribute of the object.
39
* If there is any error, the error message is added to the object.
40
* @param CModel $object the object being validated
41
* @param string $attribute the attribute being validated
43
protected function validateAttribute($object,$attribute)
45
if($this->filter===null || !is_callable($this->filter))
46
throw new CException(Yii::t('yii','The "filter" property must be specified with a valid callback.'));
47
$object->$attribute=call_user_func_array($this->filter,array($object->$attribute));