when i set model attributes before i safe the model value of POST elem gets lost?

In my actionUpdate method this happens:


if(isset($_POST['Mandant']))

		{

	print_r($_POST['Mandant']);			

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

	print_r($model->attributes);

			

	exit;

	if($model->save())

…and generates the following output:


Array

(

    [mandant_id] => 1444

    [user_id] => 7

    [kontakt_id] => 2

    [nr] => 2

    [gruppe] => privat

    [vname] => XX

    [nname] => FF

    [gebname] => XX FF

    [gebtag] => 1985-11-13

    [gebort] => 

    [strasse] => sadasd

    [plz] => 23434

    [ort] => sdfsfsdf

    [privtel] => 

    [privhandy] => 

    [privemail] => 

    [versnr] => 

    [fstand] => 

    [nationschl] => 

    [geschl] => 

    [staat] => 

)

Array

(

    [id] => 16

    [mandant_id] => 1444

    [user_id] => 7

    [kontakt_id] => 

    [nr] => 2

    [gruppe] => privat

    [vname] => XX

    [nname] => FF

    [gebname] => XX FF

    [gebtag] => 1985-11-13

    [gebort] => 

    [strasse] => sadasd

    [plz] => 23434

    [ort] => sdfsfsdf

    [privtel] => 

    [privhandy] => 

    [privemail] => 

    [versnr] => 

    [fstand] => 

    [nationschl] => 

    [geschl] => 

    [staat] => 

    [sozialvers_nr] => 

    [konto_nr] => 

    [blz] => 

    [bank] => 

    [abw_kontoinh] => 

    [create_time] => 2012-06-27 11:04:01

    [create_user_id] => 7

    [update_time] => 2012-06-27 11:04:01

    [update_user_id] => 7

)

did you notice [kontakt_id] somehow lost its value??

can somebody explain this behavior?

Adding kontakt_id to the ‘integerOnly’=>true rule fixed the problem…

still dont know why this happens :unsure:

Before adding it to that integerOnly rule, was that field in any other rule, or in the safe array?

@bennouna

No, the field was not defined in any rule.

safe array?? what do you mean by that?

correct value was in $_POST[‘Mandant’] but when $model->attributes=$_POST[‘Mandant’] was set, $model->attributes filed value was wrong… which is really weird…

That’s why you don’t get the attribute for massive assignment. Instead of explaining (badly) myself, you can understand from this wiki for instance:

http://www.yiiframework.com/wiki/161/understanding-safe-validation-rules/