Created
August 12, 2015 08:58
-
-
Save iredun/44fd97301fc054446cd4 to your computer and use it in GitHub Desktop.
Получить список разделов и их подразделов в 1С - Битрикс
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$res = CIBlockSection::GetList( | |
Array('name' => 'asc'), | |
Array('IBLOCK_ID' =>'5' , 'ACTIVE' => 'Y') | |
); | |
while ($row = $res->GetNext()) | |
{ | |
echo $row['NAME'].'<br>'; | |
$rsParentSection = CIBlockSection::GetByID($row['ID']); | |
if ($arParentSection = $rsParentSection->GetNext()) | |
{ | |
$arFilter = array('IBLOCK_ID' => $arParentSection['IBLOCK_ID'],'>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'],'<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'],'>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']); // выберет потомков без учета активности | |
$rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'),$arFilter); | |
while ($arSect = $rsSect->GetNext()) | |
{ | |
echo '---'.$arSect['NAME'].'<br>'; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
А зачем повторно получать раздел по ID, если он уже есть в первой выборке? Оптимизировал код вот так: