Get attribute in create action

I’m having troubles getting the attributes of a model after the model->save().

I even tried getting them before the save, but i still can’t get it.


$model->MyDate = date("Y-m-d H:i:s");

$MyVar = $model->MyAttribute; // this is empty


$MyVar = $model->MyAttribute; // this is empty


I know i could get it from the $_POST, but i think it would be better to get it from the model and i can’t understand why i get empty values.


Share your model`s code.

Is MyAttribute defined in the rules section of your model? Whenever you mass assign attributes, they all go through your rules method to see if they are marked as safe, else they won’t get populated.

Ok, that’s why. Sorry, i hope it will help other people who made the same mistake.