Answer the question
In order to leave comments, you need to log in
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"];
<?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>
Answer the question
In order to leave comments, you need to log in
$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 questionAsk a Question
731 491 924 answers to any question