M
M
Maxim Timofeev2016-05-29 20:05:02
Yii
Maxim Timofeev, 2016-05-29 20:05:02

How to save the data from the model in 1 DB cell?

There is a model for a form with a bunch of fields, they can change over time, etc.
There is a model for the table (user_id, data)
Question 1:
how best to store serialize, json, more options?
Question 2: What is the best way to access form model data?
$model - will give an object, which is not needed, $model->atributes only returns the field names. Something twisted me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-05-29
@webinar

how best to store serialize, json, other options?
Roughly speaking json is better and faster. Serialize is more convenient if you push objects of your own classes into the database, which you most likely do not need.
After submitting on the client, the Controller must accept the data in the same dynamic model taken from getDataAsModel(){...}, call validation and put it in the method setMyDataModel($dinModel), which will do what it needs and shove the $this->data = json_encode($data);
Docks.
www.yiiframework.com/doc-2.0/yii-base-dynamicmodel.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question