L
L
loxnemamont2016-10-24 14:40:37
1C-Bitrix
loxnemamont, 2016-10-24 14:40:37

Does the static CIBlock->GetFields() method make queries to the database?

In short:
In a component with

$res = CIBlockElement::GetList(array(), $arFilter, false, array("nPageSize" => $arParams["ITEMS_PER_PAGE"]), $arSelect);

I get a list of infoblock elements and pass them to the template, where I display them with pagination:
$res->NavStart();
while ($ob = $res->GetNextElement()) {
    $item = $ob->GetFields();
    echo $item["ID"];
    echo $item["NAME"];
    echo $item["ACTIVE"];
  }
echo $res->NavPrint("Товары");

The question is, is this implementation correct? I know that it is not the best practice to make queries to the database in the template, so I would like to know - in this situation, the method
$ob->GetFields();
makes a query to the database or operates on an existing object of the CIBElement type?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-10-24
@loxnemamont

This method is not static, the call itself tells us about it. Requests are not executed in it:

function GetFields()
{
  return $this->fields;
}

Requests are made in the $res->GetNextElement() method. In a good way, this code should be in the component, or in result_modifier.php.
UPD. If you need only those fields that are in the example, then it makes sense to write like this:
while ($item = $res->Fetch()) {
    echo $item["ID"];
    echo $item["NAME"];
    echo $item["ACTIVE"];
}

bitrixcode.ru/neochevidnye-sposoby-optimizatsii-za...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question