Yii Framework Forum: Ho to add a form field after an automatic crud generation ? - Yii Framework Forum

Jump to content

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

Ho to add a form field after an automatic crud generation ? Rate Topic: -----

#1 User is offline   jptsetung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-March 10

Posted 07 March 2010 - 12:47 PM

I've run the crud script to generate the automatic forms on a table.

Now I try to add a field into this form and it looks like it's not so easy.

I've added a property $new_text_field in my ActiveRecord class
And I've added the corresponding field in the form.

In the actionUpdate, after this line :

$model->attributes=$_POST['table'];

The property new_text_filed is not updated, despite it is in the the $_POST (I traced it).

Please help.
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 07 March 2010 - 12:51 PM

It seems that you didn't make it "safe". You should do it in the rules() method:

array('new_text_filed', 'safe')

0

#3 User is offline   jptsetung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-March 10

Posted 07 March 2010 - 01:20 PM

`yes you're right, it works. The safe validator is not clear to me "safe for massive assignments". What does i mean exactly ?
0

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 07 March 2010 - 01:50 PM

Massive assignment is: $model->attributes = $_POST['table']. It's just a loop. If $_POST['table'] array's key 'attributeName' is "safe" for $model, then it will be assigned (same as $model->attributeName = ...).

Assume, that all attributes are safe and your model has property "createTime", which must be assigned only by your program. Now, bad guys can send a POST variable createTime = 666. It will be successfully assigned and saved, and it is not good ;)
0

#5 User is offline   jptsetung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-March 10

Posted 07 March 2010 - 02:33 PM

Ah OK, thx!
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