Form fields rules based on user?

Is there a way to set form field rules for a certain users? It would be very convenient if I could do something like this:

array(‘status’, ‘safe’, ‘users’ => ‘@’))

Or a variation based on the way it works for accessRules(). Possible?

I’m trying to add a couple of admin-only fields to an update form (so I don’t have to make a whole extra form). I know I can set the scenario differently when it is an editor updating the form, but then the ‘on’ => ‘update’ rules do not cascade to the admin.

Also, if there could be multiple scenarios, this could allow for a workaround to this since I could just add the admin scenario.

Thanks!




$rules = array();

$rules[] = array('email','email');

if(Yii::app()->user->isAdmin)

    $rules[] = array('status','required');


return $rules;



you can also use scenario for this.




array(

    ...

    array('email', 'email'),

    array('status', 'required', 'on'=>'adminCreate'),

    ...

);



Hah, well that should’ve been somewhat obvious…

Thanks!