Something I misunderstand in the following:

// в POST $model->name пришло любое значение $model->name = 'test'; print_r($model->name); // Вывод 'test' // в POST $model->content['image'] пришло пустое значение $model->content['image'] = UploadedFile::getInstance($model,'content[image]'); // или $model->content['image'] = 'любойтекст'; print_r($model->content['image']); // Вывод пустой 

On the rules you can not navigate

In the content field I store various values ​​that are not required for building queries to the database, these can be meta tags, images. Then in BeforeSave, I re-encode the array $ this-> content into JSON and add it to the database.

As you can see from the code above, I just cannot reassign any element of the $ model-> content array, but I can reassign any $ model property of only the first level

    2 answers 2

    Found a way

     $content = $model->content; $content['image'] = 'bla-bla-bla'; $model->content = $content; 

    The problem is in __get and __set of parents, apparently the setter does not work correctly with the properties of level 2

    • for that minus interesting - Peresada
    • probably for the misrepresentation that "__get and __set work only with the first level of properties" - this is not so - Blacknife
    • @Blacknife In the example code in question, show that I am mistaken in the setter. Or explain why $content = $model->content; $content['anykey'] = 'bla-bla-bla'; $model->content = $content; echo $model->content['anykey']; // bla-bla-bla $content = $model->content; $content['anykey'] = 'bla-bla-bla'; $model->content = $content; echo $model->content['anykey']; // bla-bla-bla $content = $model->content; $content['anykey'] = 'bla-bla-bla'; $model->content = $content; echo $model->content['anykey']; // bla-bla-bla works, and $model->content['anykey'] = 'bla-bla-bla'; echo $model->content['anykey']; // --- $model->content['anykey'] = 'bla-bla-bla'; echo $model->content['anykey']; // --- $model->content['anykey'] = 'bla-bla-bla'; echo $model->content['anykey']; // --- no - Peresada

    Well, nothing has come to you, so it is empty. Go to the code and see what getInstance returns https://github.com/yiisoft/yii2/blob/master/framework/web/UploadedFile.php#L110 If the file came (content [image] should be the file), then the object returns UploadedFile otherwise null.

     var_dump($model->content['image']);//null 
    • Re-read carefully the code - Peresada