CActiveRecord->attributes assignment

I have a table

card_type char(3) primary key

dscp varchar(40)

pay_type char(1)

there is a statement in my controller before calling save method ( I put 2 var_dump to debug )

      var_dump( $_POST['CardType'] );


      var_dump( $model->attributes );

The first var_dump return

array(3) { ["card_type"]=> string(3) "ABC" ["dscp"]=> string(24) "Testing Testing 123" ["pay_type"]=> string(1) "D" }

and the second var_dump return

array(3) { ["pay_type"]=> string(1) "D" ["dscp"]=> string(24) "Testing Testing 123" ["card_type"]=> NULL }

It seems the assignment of "card_type" into the "attributes" not successful. Is it a bug? Thanks!


i think card_type is not an save attribute! Check whether you have rule for card_type in your rules() otherwise it would not be assigned massivly!

EDIT: My fault. I have overlooked that card_type is your primary key and this means it's definitly no safe attribute by default!


Read this http://www.yiiframew…tributes-detail


Where should I modify the safeAttributes. CActiveRecord, CModel or CFormModel?

On the other hand, is it common practice of Yii is have an autoincrement 'id' for each table?



Override safeAttributes() in your model class that extends CActiveRecord as described here: http://www.yiiframew…ute-assignments


Sorry I think I am a little bit stupid.

I put the following code in the end of CardType.php in models directory.

public functon safeAttributes()


	return array(


/* 'create'=>'card_type, dscp, pay_type',

*/ );


But I have got a blank page now. (no matter I comment the code or not)

What Yii version are you using?  what about removing the whole safeAttributes()?


it's 'public function' not 'public functon' or is this just an copy'n'paste error?!

But the much easier way would be just to make a single assignment for this attribute in your controller:




Thanks… x 10000

It is amazing!