Yii Framework Forum: Scenario - Yii Framework Forum

Jump to content

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

Scenario Rate Topic: -----

#1 User is offline   Aravind Raj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-February 13

Posted 01 April 2013 - 05:35 AM

I created a table 'userfacility' which comprise fields status, last_name,userid, facilityid, created. I made facilityid and last_name as mandatory in the model (array('facilityid,last_name', 'required')).

Then I tried to save a record for 'userfacility' through other controller by.

After $model->save();

if ($_POST['User']['facility_id'] >0)
{
$update_facility = new UserFacility('udf');
$update_facility->userid = $model->id;
$update_facility->facilityid = $model->facility_id;
$update_facility->save();
}
For this I created a rule with scenario in the 'userfacility' model. Like this

array('userid, facilityid', 'required','on'=>'udf'),

But it doesn't work it still looks for the old rule with last_name and facility_id. I don't understand why?
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,670
  • Joined: 04-March 10
  • Location:UK

Posted 01 April 2013 - 05:42 AM

The scenarios only add rules to the existing rules, so all of your existing rules still apply.
0

#3 User is offline   Aravind Raj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-February 13

Posted 01 April 2013 - 05:45 AM

Thanks Keith.

But I added a new scenario

array('userid, facilityid', 'required','on'=>'udf'),

in the 'userfacility' model.
and used it in the controller,

$update_facility = new UserFacility('udf');
Why it didn't work?
0

#4 User is offline   Aravind Raj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-February 13

Posted 01 April 2013 - 06:58 AM

One more thing, If I change the default scenario with some name like
(array('facilityid,last_name', 'required' , 'user')).


The second scenario which I created also works()
array('userid, facilityid', 'required','on'=>'udf'),

Does it means we can't use scenario's to save records, unless we gave a name to the default scenario?
0

#5 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,670
  • Joined: 04-March 10
  • Location:UK

Posted 02 April 2013 - 02:59 AM

I'm not sure what's not working for you, but if you have rules that aren't specific to a scenario, then they will apply to all scenarios. In newer versions of Yii, you can use the except clause of the rule to prevent the rule being applied on specific scenarios.
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