I’m refactoring a bunch of my own code from 1.0.12 to 1.1.3.
Now then, I used to be able to create validation rules on the fly, and depending a bit on class attributes. This doesn’t seem to work anymore; has validate() become somehow static?
To clarify, pseudocode:
public function rules()
{
return array(
array('someAttribute', 'in', 'range'=>$this->createSuitableRange()),
);
}
So, previously at least, in $this->createSuitableRange() I was able to rely on the attribute values set for $this object. Now as I’ve changed to 1.1, I’m having trouble doing this. Instead, $this object appears to have empty attribute values within the rules() function.
Is rules() called from a static context after all while validating in 1.1? Documentation seems to claim it non-static.
The validator objects only get created on first access. This can happen quite early, e.g. when you do a massive assignment. Then the safe attributues are searched which in the end triggers createValidators(). It returns a CList of all Validators.
So one idea of a dirty workaround: In beforeValidate you use getValidatorList(), clear the CList, create another list from createValidators() and merge this list back to the first CList. A bit clumsy, though…
Maybe you find a better solution. You should check the source of CModel.