Using Scenario's

Here is what I have

model:


public function rules() {

  return array(

    array('Name, FullName', 'required'),

    array('Name', 'required', 'on'=>'org'),

controller:


public function actionCreate() {

  $model = new Organization('org');

or


public function actionCreate() {

  $model = new Organization;

  $model->setScenario('org');

Is there something else I need to have to get this to work?

yes ,

I had this problem too ,

but now I have perfect solution.

your controller code is correct ,

problem in ,


array('Name, FullName', 'required'),

    array('Name', 'required', 'on'=>'org'),

when you use scenario as org , it requir "Name" field only for org , but not for others.

but see first validation rule array(‘Name, FullName’, ‘required’), here FullName is also required on all page including action with org scenario.

so , the solution is pass another scenario in first rule array(‘Name, FullName’, ‘required’),

will work 100% :)

Thanks Kiran Sharma, you are right it works!

wc