Yii Framework Forum: Fields not listed in rules are not saved - Yii Framework Forum

Jump to content

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

Fields not listed in rules are not saved Rate Topic: -----

#1 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 25 September 2009 - 03:15 PM

Hello,

why are fields who are not listed in the rules array not saved into my database?

example: Username is listed in the safeAttributes array but not in the rules array, when i fill in the form everthing is stored in my database except the field Username.

regards!
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,900
  • Joined: 04-October 08
  • Location:DC, USA

Posted 25 September 2009 - 03:29 PM

Are you using 1.1 (trunk)? If so, only fields listed in rules() can be massively assigned. safeAttributes() is removed in 1.1.
0

#3 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 25 September 2009 - 03:38 PM

View Postqiang, on 25 September 2009 - 03:29 PM, said:

Are you using 1.1 (trunk)? If so, only fields listed in rules() can be massively assigned. safeAttributes() is removed in 1.1.


yes just downloaded a 1.1-dev version this week. so the safeAttributes method is doing nothing...

Only attributes listed in the rules method will be massively assigned? Hoc can i assign fields manualy?
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,900
  • Joined: 04-October 08
  • Location:DC, USA

Posted 25 September 2009 - 03:55 PM

Yes. If an attribute doesn't need validation but you still want it to be massively assigned, you can use the 'safe' validator:
array('username', 'safe'),

0

#5 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 25 September 2009 - 04:25 PM

awesome i start to love yii :).

but how can i assign them manually like if an user update his details but not his password. so the password will be blank and have to be ignored by the AR during a update action.
0

#6 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 25 September 2009 - 05:31 PM

View Postbas_vdl, on 25 September 2009 - 04:25 PM, said:

but how can i assign them manually like if an user update his details but not his password. so the password will be blank and have to be ignored by the AR during a update action.

This is not exactly manual assigning per se. This very specific use case has been described many times before, please use the search function to find the right answer.

Manual assigning, however, is simple:
$model->attribute = $value;

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