Massive Assignment json value failed

I’m using yii framework 1.1, hosting with nginx.

Following this guide, i have posting data normally via a html form (application/x-www-form-urlencoded). On controller of create action, i can get the posted data and assign it to my model (massive assignment):


However, on another action, i got data from json (application/json), i cannot assign json data to my model.

$jsonContent = file_get_contents('php://input');


I’m sure that the data from $_POST[‘Course’] and the json from $jsonContent are the same.

I have checked the rules of model and all field are marked as save.

I’m maintaining an old system and i’m not sure if any configuration of yii framework may cause this issue. If you suspect any Yii configuration, let me know and i will check.


Did you try this?

$model->attributes=json_decode($jsonContent, true);

can you post your json structure here? it is likely you may have a schema mismatch

It works. Thanks a lot for your help. I have never known that the massive assignment just work with array :)