i'm having exactly the same difficulty to solve as you!
And i also had the same ideas about solving this issue
Cause there are many fields on my form and i can split the fields in groups of nearly identical size corresponding to the roles i used a simple solution by just splitting the fields into groups and placing them on different CTabView-Tabs.
These Tabs are then generated/shown on a role basis. This would comply with your second solution.
But this approach is not very flexible nor satisfying, so i hope we can find a better solution for this.
Perhaps extend the CHtml::active…() methods. These functions have access to the model and therefore could ask the model whether the current user has access to this field (and if so what kind of access). Depending on that, you display either the value or the form element.
In my controller I make a new update-action and create an filter-array that defines which fields are active. I keep the original update-action for use as administrator:
<?php
public function actionUpdateRole()
{
$filters=array('active'=>true,'fields'=>array('ordernr'=>true));
$this->actionUpdate($filters);
}
public function actionUpdate($filters=array())
{
...
$this->render('update',array(... ,'filters'=>$filters));
...
}
Now i just call …index.php?r=controller/update/role&id=… and every EHtml-field expect 'ordernr' is inactive .
Edit: changed default from active to inactive. Now you have to set the fields which should be editable.