How to assign attributes and rules to a model after load?

Dear Friends,

I am working on creating a form builder which loads form fields from an XML file and renders the HTML. I have multiple XML files, each has different form fields depending on what the user requires. I also have a database table which has all the columns which the forms require.

The issue I am having is creating a model that only loads the attributes and rules required for the generated form. Apart from overwriting the CModel class so validators and attributes can be set during runtime, are there any other ways for doing this?

Thank you in advance for you help.

Best regards,

Alex

An update regarding this issue:

I have figured out that you can load the rules array from the model’s properties as shown below:




class MyClass extends CActiveRecord {

    public $customRules;


    public function rules() {

        return $this->customRules;

    }

}



I can then set the custom rules just after construction before createValidators() is called.

Additionally I could load all the attributes from the database table and when calling save() I can specify which attributes need to be saved.

Can anyone see any problems with using the above methods?

All the best,

Alex

You can surely set rules during runtime using:

CAccessControlFilter->setRules()

Thank you for your reply saegeek, however I am not trying to set access rules, I am loading an AR and I want it to load custom rules and attributes after load. I think I have solved the issue in my reply above.