0

написал функцию которая записывает данные в бд, все работает норм пока не доходит до заполнения таблицы descriptions точнее до строки kitchen_space, данные заполняются по 12 строк и выпадает ошибка. Помогите плизб в чем дело не пойму.

foreach ($this->json as $item){
      $idSales = 0;
      $idOffer = 0;

      $model = SalesAgents::find()->one();
      if(!$model || $model->name != $item['sales-agent']['name']){
        $model = new SalesAgents();
        $model->category = $item['sales-agent']['category'];
        $model->name = $item['sales-agent']['name'];
        $model->url = $item['sales-agent']['url'];
        $model->phone = $item['sales-agent']['phone'];
        $model->save();
      }
      if($model->save()){
        $idSales = $model->id;
      }


      $offer = new Offer();
      $offer->sales_id = $idSales;
      $offer->internal_id = $item['internal-id'];
      $offer->creation_date = $item['creation-date'];
      $offer->category = $item['category'];
      $offer->built_year = $item['built-year'];
      $offer->building_state = $item['building-state'];
      $offer->type = $item['type'];
      $offer->property_type = $item['property-type'];
      $offer->mortgage = $item['mortgage'];
      $offer->new_flat = $item['new-flat'];
      $offer->save();

      if($offer->save()){
        $idOffer = $offer->id;
      }

      $price = new Price();
      $price->offer_id = $idOffer;
      $price->value = $item['price']['value'];
      $price->currency = $item['price']['currency'];
      $price->save();

      $location = new Location();
      $location->offer_id = $idOffer;
      $location->country = $item['location']['country'];
      $location->address = $item['location']['address'];
      $location->location_name = $item['location']['locality-name'];
      $location->save();

      $descriptions = new Descriptions();
      $descriptions->offer_id = $idOffer;
      $descriptions->description = $item['description'];
      $descriptions->kitchen_space = $item['kitchen-space']['value'] . $item['kitchen-space']['unit'];
      $descriptions->living_space = $item['living-space']['value'] . $item['living-space']['unit'];
      $descriptions->area = $item['area']['value'] . $item['area']['unit'];
      $descriptions->rooms_type = $item['rooms-type'];
      $descriptions->rooms = $item['rooms'];
      $descriptions->bathroom_unit = $item['bathroom-unit'];
      $descriptions->ready_quarter = $item['ready-quarter'];
      $descriptions->floors_total = $item['floors-total'];
      $descriptions->floor = $item['floor'];
      $descriptions->building_type = $item['building-type'];
      $descriptions->save();

    }
Undefined index: value
1. in /var/www/yii2/basic/controllers/SiteController.phpat line 127
118119120121122123124125126127128129130131132133134135136      $location->offer_id = $idOffer;
      $location->country = $item['location']['country'];
      $location->address = $item['location']['address'];
      $location->location_name = $item['location']['locality-name'];
      $location->save();
 
      $descriptions = new Descriptions();
      $descriptions->offer_id = $idOffer;
      $descriptions->description = $item['description'];
      $descriptions->kitchen_space = $item['kitchen-space']['value'] . $item['kitchen-space']['unit']; ОШИБКУ ТУТ ВЫДАЕТ
      $descriptions->living_space = $item['living-space']['value'] . $item['living-space']['unit'];
      $descriptions->area = $item['area']['value'] . $item['area']['unit'];
      $descriptions->rooms_type = $item['rooms-type'];
      $descriptions->rooms = $item['rooms'];
      $descriptions->bathroom_unit = $item['bathroom-unit'];
      $descriptions->ready_quarter = $item['ready-quarter'];
      $descriptions->floors_total = $item['floors-total'];
      $descriptions->floor = $item['floor'];
      $descriptions->building_type = $item['building-type'];

если закомментировать эту код заполнения этой таблицы, то все остальное работает корректно

1 ответ 1

0

В ошибке сказано, что нет такого ключа с именем value. Значит в перечисляемом массиве у одного из значений нет такого ключа

2
  • в том то и дело что есть ``` Array ( ... [kitchen-space] => Array ( [value] => 15,79 [unit] => кв.м. ) [living-space] => Array ( [unit] => кв.м. [value] => 12,77 ) [area] => Array ( [unit] => кв.м. [value] => 40,69 ) ... ) ``` вот эти части массива вызывают проблему
    – uglenpish
    31 янв 2021 в 18:34
  • 1
    На какой-то итерации может и есть, а на какой-то - нет 31 янв 2021 в 18:37

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.