How do I make a field read only

How do I make a field read only, for instance for a create_date of a record? Can I add somehow an attribute to the rules of the model to make a field read only (in the sense that the field is displayed but not editable by the user, when a record is updated?

If an attribute has no rules assigned to it, it’ll be considered unsafe which will prevent it from being filled by massive assignments. Apart from that: Just delete the according fields out of your forms.

why don’t you use readonly element in view file?

Another idea:

You can set the ‘disable’ htmloptions. Lets say you have a textfield and you want to display the date to the user but do not want them to edit it. You will also need to follow sourcerer’s advice on rules or else the user could construct their own form and post to the server and work around you.

Third option:

Instead of displaying it as a form input, just echo it out with CHtml::encode.

The thing is, I do want them displayed. The view uses renderPartial. And I wondered whether it’s possible to define in the model that the field is not editable.

Then don’t let the form render it. You know, the _form view ::)

Thanks for all the patience with my utter newbie questions. All your suggestions have been most helpful.