Yii Framework Forum: Rules for different actions in same model. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Rules for different actions in same model. Rate Topic: -----

#1 User is offline   Arvind 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 03-October 09
  • Location:Calgary, AB, Canada

Posted 23 October 2009 - 02:37 AM

Hello,

In my controller i have two actions, MyProfile and Update.
Some rules are common, while some are unique to each action.

this is how i am trying to seperate the rules
array('password1','CheckCurrentPassword','on'=>'MyProfile' ),
array('EMAIL', 'CheckIfUnique', 'on'=>'Update'),

Somehow, when i specify the 'on' attribute, the control does not enter functions 'CheckCurrentPassword' or 'CheckIfUnique'.

If i take out the on clause, then all seems to work fine, but the validation rules clash for all the actions.

Can anybody tell me if I am doing something wrong ?

thanks
Arvind
0

#2 User is offline   Dave 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 187
  • Joined: 09-October 08

Posted 23 October 2009 - 03:01 AM

you must specify the scenario if you validate the model.
0

#3 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 23 October 2009 - 03:01 AM

View PostArvind, on 23 October 2009 - 02:37 AM, said:

Hello,

In my controller i have two actions, MyProfile and Update.
Some rules are common, while some are unique to each action.

this is how i am trying to seperate the rules
array('password1','CheckCurrentPassword','on'=>'MyProfile' ),
array('EMAIL', 'CheckIfUnique', 'on'=>'Update'),

Somehow, when i specify the 'on' attribute, the control does not enter functions 'CheckCurrentPassword' or 'CheckIfUnique'.

If i take out the on clause, then all seems to work fine, but the validation rules clash for all the actions.

Can anybody tell me if I am doing something wrong ?

thanks
Arvind


the on index is for the scenario name. so you can have 'on'=>'update'

when you instantiate the model like $obj = new NameOfModel();

you then set the secnario in 1.1 like $obj->scenario = 'update';

then the rules where on is set to update will apply along with those where on is not specified.
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#4 User is offline   Arvind 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 03-October 09
  • Location:Calgary, AB, Canada

Posted 23 October 2009 - 03:07 AM

View Postjayrulez, on 23 October 2009 - 03:01 AM, said:

the on index is for the scenario name. so you can have 'on'=>'update'

when you instantiate the model like $obj = new NameOfModel();

you then set the secnario in 1.1 like $obj->scenario = 'update';

then the rules where on is set to update will apply along with those where on is not specified.



Great...that was super fast. Thanks so much.

I specified my scenario in this way.

$model->validate('<myscenario>');

Is this also a correct way of doing it, or, will it be deprecated ?


thanks
Arvind
0

#5 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 23 October 2009 - 10:12 AM

View PostArvind, on 23 October 2009 - 03:07 AM, said:

Great...that was super fast. Thanks so much.

I specified my scenario in this way.

$model->validate('<myscenario>');

Is this also a correct way of doing it, or, will it be deprecated ?


thanks
Arvind


i think that should work in all versions prior to 1.1a
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#6 User is offline   sonam 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 10-September 11

Posted 18 November 2011 - 11:16 AM

thanks helped great
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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