First we have to declare a static function in Role model to fetch the role names in an array format.
Here array value would be role.name and array key would be role.id
class Role extends CActiveRecord
{
public static function fetchRoleNames()
{ $arr=array();
$roles=Role::model()->findAll();
foreach($roles as $role)
{
$arr[$role->id]=$role->name;
}
return $arr;
}
}
Then in your views/user/_form.php, make following changes for role_id.