$Model->Attributes Don't Set A Value

Dear all,

I use $model->attributes = $_POST[‘my_model_name’] to assign my post values to the model instance. One field of my post is now not assigned to my model and I don’t know why.

This is my post-dump:


array(5) {

  ["bdk_number"]=>

  string(4) "4712"

  ["region_id"]=>

  string(1) "1"

  ["name"]=>

  string(28) "XYZ"

  ["has_adress"]=>

  string(1) "0"

  ["position_id"]=>

  string(1) "1"

}

This is my code to assign in my controller class:




var_dump($_POST['Club']);

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

var_dump($model->attributes);

and this is the dump after:




array(9) {

  ["id"]=>

  string(1) "1"

  ["bdk_number"]=>

  string(4) "4712"

  ["region_id"]=>

  string(1) "1"

  ["name"]=>

  string(28) "XYZ"

  ["has_adress"]=>

  string(1) "0"

  ["adress_id"]=>

  string(1) "0"

  ["position_id"]=>

  string(1) "0"

  ["created_at"]=>

  string(19) "2013-05-02 13:19:20"

  ["updated_at"]=>

  string(19) "2013-05-08 13:48:07"

}

Updating the name-attribute is working and the position_id not.

What can be the reason?

missing validation rules. massive assignements works only for attributes that have validation rules in current scope and are not marked as ‘unsafe’.

Imagine that “fieldName” is your attribute’s name.

Then, in your model you should have something like this:




array('fieldName', 'safe'),



This means that if you make a masive assignment


$model->attributes = $_POST['my_model_name']

, the attribute fieldName will be updated.

Greetings.