Answer the question
In order to leave comments, you need to log in
How to add data to a model in a loop in Yii2?
Hello. The essence of the problem on the fingers is as follows:
1. There are goods
2. There are technical characteristics
There can be many characteristics for one product.
I created a form from two models, the number of characteristics can be increased or decreased using js, the generated name for each new field looks like this:
name='TechSpec[0][title]'
name='TechSpec[1][title]'
$techSpech = [new common\models\TechSpec]
/*
* потом loadMultiply при загрузке возвращает false если больше чем одна характеристика
* добавлена
* При удачной загрузке беру длину массива и циклом создавая новые объекты сохраняю
* новые данные по индексу
*
*/
Answer the question
In order to leave comments, you need to log in
1. How do update examples differ from create if the save() method is both there and there, if you use the update() method, it’s another matter, but there is hardly a lot of information about it in google.
2
$techSpech = [new common\models\TechSpec]-what is this? Why not
$techSpech = new common\models\TechSpec();
? Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question