Yii Framework Forum: Validating a scenario in 2 ways? [SOLVED] - Yii Framework Forum

Jump to content

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

Validating a scenario in 2 ways? [SOLVED] how to validation is better, in declaration or validate() method Rate Topic: -----

#1 User is offline   Nacesprin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 04-April 10
  • Location:San Fernando - Cadiz - Spain

Posted 03 June 2010 - 09:42 AM

Hello. I wonder what is the difference if we validate a model in follow two ways:

$model = new User('scenarioName');
//and then....
$model->validate()

or the second manner:

$model = new User();
//and then....
$model->validate('scenarioName');


What are the differences?

Thanks.

I hope I don't answer any stupid question.
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 03 June 2010 - 10:23 AM

Your second example is wrong. validate() expects attributes, not a scenario.
0

#3 User is offline   Nacesprin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 04-April 10
  • Location:San Fernando - Cadiz - Spain

  Posted 03 June 2010 - 05:34 PM

View PostMike, on 03 June 2010 - 10:23 AM, said:

Your second example is wrong. validate() expects attributes, not a scenario.


Then this example is wrong?

http://php-thoughts....tion-scenarios/
0

#4 User is offline   tri 

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

Posted 03 June 2010 - 05:54 PM

View PostJavier, on 03 June 2010 - 05:34 PM, said:

Then this example is wrong?

http://php-thoughts....tion-scenarios/


It's correct as of 1.0.x
http://www.yiiframew...validate-detail

The syntax was changed in 1.1
http://www.yiiframew...validate-detail

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
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