S
S
serg78ant2018-04-17 13:53:41
1C-Bitrix
serg78ant, 2018-04-17 13:53:41

How to get all sections of an infoblock, with subsections of all levels of nesting?

Actually the whole point of the question is stated in the title of the question.
Tried using section.list but it only gives sections without subsections.
I would like to do without additional. requests via getlist.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-04-17
@serg78ant

You can specify the desired sampling depth in the component.
Or write your own component
https://dev.1c-bitrix.ru/api_help/iblock/classes/c...
The examples have a selection of subsections

A
Andrey Nikolaev, 2018-04-18
@gromdron

I re-read and did not understand the question at all. There is also a standard CIblockSection::GetList() which for 1 request perfectly gets everything with nesting.
In the spoiler, I indicated the code that will get all sections, including subsections for a specific infoblock, sorted by the left indent (ie, top to bottom, left to right). And all this for 1 request to the database using the API.

An example that I tested
/**
 * Всегда считаем что модуль установлен, 
 * поэтому просто подключаем его
 */
\Bitrix\Main\Loader::IncludeModule('iblock');

/**
 * У меня для тестирования инфоблок с номером 5,
 * у тебя может быть любой другой инфобло
 * 
 * @var array Параметры фильтрации
 */
$arFilter = [
  'IBLOCK_ID' => 5
];

/**
 * В Битриксе разделы хранятся по принципу Nested sets
 * 
 * @var array Параметры сортировки
 */
$arOrder = [
  'LEFT_MARGIN' => 'ASC'
];

/**
 * @var array Поля разделов
 */
$arSelect = [
  'ID',
  'LEFT_MARGIN',
  'DEPTH_LEVEL',
  'NAME'
];

$resSections = \CIBlockSection::GetList($arOrder, $arFilter, false, $arSelect);

while( $arSection = $resSections->fetch() )
{
  var_dump($arSection);
}

What did I do wrong and where am I doing wrong?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question