Yii Framework Forum: Question about controller create by CRUD - Yii Framework Forum

Jump to content

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

Question about controller create by CRUD Rate Topic: -----

#1 User is offline   echo66 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-May 10

Posted 06 May 2010 - 06:23 PM

I'm a newbie at using frameworks and i have a question.

What does "new User('search');" do? I don't understand the use of the 'search' argument.

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new User('search');
		if(isset($_GET['User']))
			$model->attributes=$_GET['User'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}


Thanks in advance.
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 06 May 2010 - 06:45 PM

View Postecho66, on 06 May 2010 - 06:23 PM, said:

I'm a newbie at using frameworks and i have a question.

What does "new User('search');" do? I don't understand the use of the 'search' argument.

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new User('search');
		if(isset($_GET['User']))
			$model->attributes=$_GET['User'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}


Thanks in advance.


It initializes the 'scenario' property to 'search' instead of the default 'insert'. See also:
http://www.yiiframew...onstruct-detail

I'm not sure about the reason, but the effect would be that all the searchable attributes can be massively assigned in the statement
$model->attributes=$_GET['User'];

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   echo66 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-May 10

Posted 07 May 2010 - 06:44 AM

Thanks for the explanation but im having a hard time understanding what scenarios are.

I have read the documentation "Creating a Model" and search in google about it and i still don't get it.
0

#4 User is offline   echo66 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-May 10

Posted 07 May 2010 - 06:49 AM

seems i jumped one line in my reading about scenarios ;D

so...

$model=new LoginForm;
$model->scenario='login';
if(isset($_POST['LoginForm']))
    $model->attributes=$_POST['LoginForm'];


so, to define a scenario is just like that? Seems easy. :lol:

Sorry again for the dumb questions....i'm new to the framework field (ANY FRAMEWORK ;D )
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