Using Form Attributes Not In Model

Hi All

I’m working on my second Yii application and I must say it is quite a high learning curve. (I’m still fairly new)

I don’t know if this is possible but can I accept a custom attribute in a form that is not in my DB as a field.

This model (Orders) have a user_name and user_email field.

I basically want a drop down of another model (Users) to look up and save the name and email once the form has been validated to the Orders model.

The reasoning why i don’t want a relation between the two tables is if a user is deleted I still want to retain the user’s name and email on the order.

When I try and add a drop down with any kind of id on my _form I start getting errors. Not defined.

Where do I have to define it?

Regards

Johan

South Africa

Well to create a non db attribute in model class you can define public variable in your model class and define them in your model rules also for validation purpose then you can access that attributes too in your form.




public $customAttr;


And in rule section 


array(

 'customAttr','required' //you can change it according to your need

),


And now you can use like $model->customAttr;



I hope you got my point here.

Thank you for above. Sorry for late reply.

I was also thinking one could simply add an <input type=hidden /> tag. And get the value in the controller.

But your method seems like the more acceptable way of doing it.

Thanks again

Regards

Joe

Deleted.