class MyModel extends CActiveRecord { public function beforeValidate() { parent::beforeValidate(); // Dynamically add a validation rule $this->validatorList->add(CValidator::createValidator('required', $this, 'new_attribute')); return true; } }
class MyModel extends CActiveRecord { public function beforeValidate() { parent::beforeValidate(); // Modify the data of the model $this->new_attribute = strtoupper($this->new_attribute); return true; } }In this example, we modify the data of the model's new_attribute property by converting it to uppercase before the validation rules are applied. Package/Library: The examples provided are using the CActiveRecord class which belongs to the Yii framework. Therefore, the package/library being used is Yii framework itself.