Yii Framework Forum: Failed To Assign Unsafe Attribute - Yii Framework Forum

Jump to content

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

Failed To Assign Unsafe Attribute Rate Topic: -----

#1 User is offline   nekulin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-February 12

Posted 02 January 2013 - 08:13 AM

Question: "Why handle field if it is not described in the model, and write to the log error".
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('email, password', 'required', 'on' => 'registration'),
        array('is_real', 'numerical', 'integerOnly'=>true),
        array('email', 'length', 'max'=>150),
        array('cat', 'length', 'max'=>255),
        array('password', 'length', 'max'=>32),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, email, cat, password, is_real', 'safe', 'on'=>'search'),
    )
}


Error
Failed to assign unsafe attribute "region_id" class "RegistrationUser".
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 02 January 2013 - 08:17 AM

/* moved from Bug Discussions as that forum is for bugs in Yii, not bugs in your own code */
"Less noise - more signal"
0

#3 User is offline   nekulin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-February 12

Posted 02 January 2013 - 08:21 AM

View Postjacmoe, on 02 January 2013 - 08:17 AM, said:

/* moved from Bug Discussions as that forum is for bugs in Yii, not bugs in your own code */

I would like to know where the error in my code
0

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 02 January 2013 - 08:34 AM

You did not make a rule for it.

So either make one, or mark it as a safe attribute. See the docs if you're unsure about how to do this.


BTW: sometimes I only have time to moderate. ;)
"Less noise - more signal"
0

#5 User is offline   nekulin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-February 12

Posted 02 January 2013 - 08:46 AM

View Postjacmoe, on 02 January 2013 - 08:34 AM, said:

You did not make a rule for it.

So either make one, or mark it as a safe attribute. See the docs if you're unsure about how to do this.


BTW: sometimes I only have time to moderate. ;)

Yes all right I'm not prescribed to him validation! Because it's a fake field, which was not there.
The main question: How not to handle the fields on which are described in the model, which will improve productivity and similar errors.
0

#6 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 02 January 2013 - 08:49 AM

If it's a fake field then it probably belongs in a FormModel, not a Model. :)
"Less noise - more signal"
0

#7 User is offline   nekulin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-February 12

Posted 02 January 2013 - 08:59 AM

View Postjacmoe, on 02 January 2013 - 08:49 AM, said:

If it's a fake field then it probably belongs in a FormModel, not a Model. :)


Yes exactly.
The task of such
1) Make the registration form
There will be 2 forms on the type of user.
2) it's Safe to pass values from the form in the model, so there was no error as it is now.
3) And save)
And there's 2 problems
1) the Form of the grant error when processing is not described fields(fakes)
2) the Model of the form takes extra fields that do not need her
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