S
S
SteepNET2020-03-02 22:52:00
1C-Bitrix
SteepNET, 2020-03-02 22:52:00

Display the name of the element "binding to elements" Bitrix?

Good afternoon!
In init.php through the API I want to get the NAME of the element "binding to elements". I'm trying this way.

$res = CIBlockElement::GetProperty($IBLOCK_ID, $ELEMENT_ID, array("sort" => "asc"), Array("CODE"=>"TOVAR"));
    while ($ob = $res->GetNext()) {
        $TOVAR_NAME = $ob['VALUE'];
    }

But here I get only its ID, and I can't get the name of this element in any way...

In the infoblock element, there is a property with the "binding to elements" type. When you select in which its ID is affixed, when you click on "...", just a directory with names is displayed. Here is the name of the selected element and I just need to get it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-03-02
@SteepNET

The name of the element is not stored in the property, only its ID is stored.
Therefore, you first get its ID as you did and make a second request CIBlockElement::GetByID or even better CIBlockElement::GetList, that is, you get the data of the element itself.

$res = CIBlockElement::GetProperty($IBLOCK_ID, $ELEMENT_ID, array("sort" => "asc"), Array("CODE"=>"TOVAR"));
while ($ob = $res->GetNext()) {
  $id = $ob['VALUE'];
  $element = CIBlockElement::GetList([], ['=ID' => $id], false, false, ['ID', 'NAME'])->Fetch();
}

Accordingly, $element['NAME'] will contain your name.
You can also like this
$element = CIBlockElement::GetList(
  [],
  [
    'IBLOCK_ID' => $IBLOCK_ID,
    '=ID' => $ELEMENT_ID
  ],
  false,
  false,
  ['ID', 'PROPERTY_TOVAR.NAME']
)->Fetch();

In this form, the element name will be $elemen['PROPERTY_TOVAR_NAME']
If the property is multiple, these methods are also applicable, but not correct. Then it's better to collect all the element IDs in an array and make only one query to the database instead of queries in a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question