How to define scenarios?

Hi folks,

I’d saw many examples showing how to build a user model (username, password, role, etc…) and how to define the validation rules.

but theres one thing that I dont understand until now. How this scenarios really works?

Most of examples looks like follows:






function rules() {


  return array(


    array('password', 'required', 'on'=>'registry'),


  );


}




but, where this ‘registry’ word comes from?

I can’t found any wiki page talking about this feature…

I thank u for any help.

See CModel::rules and CModel::scenario.

The scenario is passed as parameter to create method of model.

Like in the actionAdmin:


$model=new Project('search');

Thanks guys!

Hi zaccaria,

Your answer was helpful, however, it only explains how actionAdmin gets the scenario ‘search’. What about scenarios like ‘insert’, ‘update’, ‘login’, ‘register’, where are these defined? I understand I can manually set the scenario to some other values but what sets these ‘default’ scenarios in the first place, other than the ‘search’ from actionAdmin?

I was at a point thinking that the scenario in actionCreate was ‘create’, I then realized that the scenario is ‘insert’ instead.

Maybe I am missing something somewhere. Some explanation will be very much appreciated. Thanks!

As a quick reply, as far as I can remember the ‘insert’ and ‘update’ scenarios are default ones defined in the base model logic depending on whether the model is a new record or not.

‘search’ is not a default scenario but is user by Gii for defining search rules and then passed in the model construction in the admin view, in the same way that any other scenario that you might invent rules for should be.