External Filter Validator Function?

Well,

We may use the filter validators in models this way:


public function rules()

{

   return array

   (

      array('myAttribute', 'filter', 'filter' => array($this, 'someFunction')),

   }

}


public function someFunction($attribute)

{

   return 'Ho ho ho ' . $attribute;

}

This is working well presuming ‘someFunction’ is defined within the model class. But how to use a ‘shared’ library of filter functions - e.g. function stored in a helper file?

Any ideas? - Thanks ahead!

would behavior concept fits here?

Perhaps, I need to improve my uderstanding of this concept first :lol:

class extends functions vertically;

behavior reuse functions horizontally;

A possible solution

Define the library as class usting static methods




// An example class with static method

class MyClass {

    public static function myCallbackMethod($param) {

        return $param . 'Hello World!';

    }

}



Then define the rule:




      array('myAttribute', 'filter', 'filter' => array('MyClass', 'myCallbackMethod')),



Consider also the possibility to use anonymous function (PHP >= 5.3):




      array('myAttribute', 'filter', 'filter' => function($param) {return $param . 'Hello World!';} ),