Answer the question
In order to leave comments, you need to log in
How to add array fields to database in Yii2?
Actually, when ActiveForm sends array fields with names like "Model[name][0]" via PJAX, no value comes to the model, i.e. the variable doesn't even exist. Complains when submitting that the variable must be a string. If to cut off in model check on type (string), then on POST event the variable does not exist.
How can this scourge be overcome?
Answer the question
In order to leave comments, you need to log in
1. In the validation, remove the string check and put safe, or write your own opening array validator.
2. If you need to save the entire array into one database cell, then you can convert the array to json in beforeValidete, then checking for a string should work.
3. You probably have an incorrect structure and the data that is in the array should be stored in a separate table with a hasMany connection, then this array should not be validated in this model, it will be validated in another, and there will already be rows.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question