M
M
Maxim Volkov2019-09-23 12:44:14
1C-Bitrix
Maxim Volkov, 2019-09-23 12:44:14

Bitrix GetByID, I'm getting an infoblock element - a problem with data caching. How to decide?

The site has two infoblocks: one contains articles displayed by the news component, the other contains the data of the authors of these articles.
When viewing the detailed pages of news, it is necessary to display the data of their authors from another infoblock.
When viewing the detailed page of the news, from the property binding to the element, I receive and pass the data of the author's ID from the component using the global array $GLOBALS

$GLOBALS["AUTOR_ID"] = $arResult["PROPERTIES"]["AUTOR_ID"]["VALUE"];

To display the author's data, I get the infoblock ID data from the Global Array and extract the author's data using CIBlockElement::GetByID($id_autor) , and then display it in the template.
<?php
if ($GLOBALS["AUTOR_ID"]) {
  $id_autor = $GLOBALS["AUTOR_ID"]; // получаю ID элемента инфоблока
  unset($GLOBALS["AUTOR_ID"]);
  }else{
  $id_autor = 2; // // Если данные не получены, задан ID элемента
  }
$res = CIBlockElement::GetByID($id_autor);
  if($ar_res = $res->GetNext())
?>	
    
<div class="card mb-4">	
  <div class="view overlay">
    <img src="<? echo CFile::GetPath($ar_res["PREVIEW_PICTURE"]); ?>" class="card-img-top" alt="Печник <?=$ar_res["NAME"];?>">
    <a><div class="mask rgba-white-slight waves-effect waves-light"></div></a>
  </div>
  <div class="card-body">
    <h5 class="card-title dark-grey-text text-center grey lighten-4 py-2">
      <strong><?=$ar_res['NAME'];?></strong>
    </h5>
    <p class="mt-3 dark-grey-text font-small text-center">
      <em><?=$ar_res["PREVIEW_TEXT"];?></em>
    </p>
  </div>
</div>

In this case, the code works, but when you go to the pages of other authors, the data does not change, more precisely, it changes only after updating the page cache.
I believe the problem is related to caching.
How to solve the problem with data caching, make sure that when visiting the pages of other authors, the data of their authors changes?
Perhaps the problem can be solved in another, more rational way. I ask for advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-09-23
@voland700

$GLOBALS["AUTOR_ID"] = $arResult["PROPERTIES"]["AUTOR_ID"]["VALUE"]; - this is most likely in your template or in result_modifier.php. Or maybe in a self-made component, but in a cached block.
You need to move the setting of this variable outside of the cached area. Let's say component_epilog.php - there is a place for such things.
In general, passing through a global variable is bad, I think. It's better to use page properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question