S
S
serik2020-09-14 20:46:46
1C-Bitrix
serik, 2020-09-14 20:46:46

How to correctly collect all sections and subsections of the Bitrix infoblock?

Please tell me how can I correctly collect all sections and subsections of the Bitrix infoblock?
Precisely so that they are ordered with links?
I tried to do it through CIBlockSection::GetList but they all go without nesting.

if(CModule::IncludeModule("iblock"))
{
    $db_res = CIBlockSection::GetList(
        array(),
        array("IBLOCK_ID" => 2),
        false,
        array('*'));
    while($section = $db_res->Fetch()) {
        echo'<pre>';var_dump($section);echo '';
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
serik, 2020-09-14
@black_xe

I found a solution in the documentation, the option suited me:

if (CModule::IncludeModule("iblock")) {
    $filter = [
        'IBLOCK_ID' => 2,
    ];
    $select = [
        'NAME',
        'SECTION_PAGE_URL',
    ];

    $dbSection = CIBlockSection::GetList(
        [
            'LEFT_MARGIN' => 'ASC',
        ],
        array_merge(
            [
                'ACTIVE' => 'Y',
                'GLOBAL_ACTIVE' => 'Y',
            ],
            is_array($filter) ? $filter : []
        ),
        false,
        array_merge(
            [
                'ID',
                'IBLOCK_SECTION_ID',
            ],
            is_array($select) ? $select : []
        )
    );
    while ($arSection = $dbSection->GetNext(true, false)) {
        $SID = $arSection['ID'];
        $PSID = (int)$arSection['IBLOCK_SECTION_ID'];
        $arLincs[$PSID]['CHILDS'][$SID] = $arSection;
        $arLincs[$SID] = &$arLincs[$PSID]['CHILDS'][$SID];
    }
    $arResult['SECTIONS'] = array_shift($arLincs);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question