scenario with parameter

Hi all,

can I define scenario with parameter ?

for example : $model = new job(‘scenario’,$params);

how to do that ?


Yes you can define scenario with parameter… but that is included within the class constructor of the model

 $model = new Job('search'); // creating a model with scenario search

If you wish to include more parameters , then you need to use createComponent -remember, all is a component

 $model = Yii::createComponent(array('class'=>'Job','scenario'=>'search')); 

thanks for your quick reply Antonio,

but I need to pass the parameter to the scenario.

so, with your example, if I put id as parameter, how to pass $id to search scenario ?

maybe in model look like this :

public function search($id)


return blablabla;


so I can call like in controller like : $model = new job(‘search’,$id);

that is my question.

anyway, I just know that we can setscenario for the model. for now that is my solution.

$model = $this->loadModel($id);