class Advertisement extends CActiveRecord
{
public $entityID;
private $_rules = array();
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function rules()
{
return $this->_rules;
}
public function addRule($rule)
{
$this->_rules[] = $rule;
}
}
Controller code:
public function actionCreate()
{
$a = new Advertisement;
$a->addRule(array('entityID', 'numerical', 'integerOnly' => true));
$a->entityID = 'string';
var_dump($a->validate());
}
Thanks. Don't forget dinamic relations() too. It needed for write complex AR behaviors like Entity-Attribute-Value behavior for CakePHP and Ruby on Rails.
Today i hack ‘columns’ property of CActiveRecordMetaData to make rules() and relations() work. But it’s not good method, native support for this operations should be fine.