Yii Framework Forum: scenario with parameter - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

scenario with parameter Rate Topic: -----

#1 User is offline   jimmi nababan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 12-October 09

Posted 26 October 2011 - 12:54 AM

Hi all,

can I define scenario with parameter ?

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

how to do that ?

thanks.
0

#2 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

Posted 26 October 2011 - 01:56 AM

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')); 

┬┐How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#3 User is offline   jimmi nababan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 12-October 09

Posted 26 October 2011 - 02:05 AM

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);
$model->setScenario('scenario');


:)

View PostAntonio Ramirez, on 26 October 2011 - 01:56 AM, said:

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')); 


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users