Could not make filterValidator work...

I have been trying to define an anonymous function in my model’s validation rules as follows:


public function rules() {

  return [

     [['field1','field2','field3'], 'filter',

         'filter'=>function($value) {

           $value = trim($value);

           if (empty($value)) return null;

           return $value;

         }

     ],

     // Other validation rules      

   ];

}



This definition creates a strange behavior, the session POST value is not set properly and Yii Debugger does not show at the bottom of the page! I have looked everywhere and it seems correct to me. Note that if I modify the rule as follows:


public function rules() {

  return [

     [['field1','field2','field3'], 'nullSetter', 'SkipOnEmpty' => false],

     // Other validation rules      

   ];

}



and the nullSetter function is exactly as above, everything works juts fine. What am I doing wrong? Can this be a bug?

Thank you!

OK, I found the reason why in this topic http://www.yiiframework.com/forum/index.php/topic/71003-potential-pitfall-storing-models-in-session-variables/

I do store my model in the session and this explains why I am getting the problem…