Multiple validations per Model?

I have a User model. When users themselves register (1), they can enter only so much information. When an admin makes a user (2), they can enter everything. The validation rules of (1) are almost all used in (2) and a few more are made for (2).

How do I configure a FormModel so it understands this, without repeating myself in entirely different FormModels?

I could create PublicUserSignupForm and a AdminUserSignupForm that extends PublicUserSignupForm and fiddle with the rules method… I think…

Could I also use the on options in the rules? For instance




array('username', 'required', 'on' => 'publicSignup, privateSignup'),

array('username', 'onlySpecificCharacters', 'on' => 'publicSignup'),



How would the on values be used?

Which is better? (Or: which works?)

In the guide new User and new LoginForm are used together (or just both?) with scenario’s “login” and “register”.

It’s very unclear how they’re supposed to be used and what’s what…

PS. How do I inline code? \[code\] makes a block element…

Also, if my custom model method onlySpecificCharacters depends on context (let’s say an object that’s ‘stored’ in the Controller), how would I reach that context from within the model?

All rules you listed will work correctly.

The example of the guide maybe is not the best one, but the philosophy is to list all attributes that have to be validated in each scenarios.

The ‘on’ values are called scenario’s in Yii.

Definitive Guide - Working with Forms

How to define scenarios?

Usefulness of scenarios