Answer the question
In order to leave comments, you need to log in
Why doesn't Yii guard linked models like in the recipe?
Good afternoon,
I wanted to do it like here yiiframework.ru/doc/cookbook/ru/model.save.related.data in the documentation.
There is a Hotels model and a rooms relation in this model: 'rooms '=>[self::HAS_MANY, 'Rooms', 'hotel_id']
I submit the form, $_POST prints out all the data, but no data is entered into the rooms relation , an example is given below.
Perhaps the documentation meant not a relation, but an array?
if(isset($_POST['Hotels']))
{
$model->setAttributes($_POST['Hotels'], true);
$arr = [];
// $model->rooms= []; так тоже ничего не заносится, если как массив объявить
foreach($_POST['Rooms'] as $room)
{
$roomModel = new Rooms();
$roomModel->setAttributes($room, true);
$model->rooms[] = $roomModel;
$arr[] = $roomModel;
}
// ничего не выводит
My::printArr($model->rooms);
// Выводит массив моделей
My::printArr($arr);
$model->save();
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question