Documentation

GetIBlockSectionList

CDBResult
GetIBlockSectionList (
 int iblock_id, 
 int section_id = false, 
 array order = Array("LEFT_MARGIN"=>"ASC"), 
 int cnt = 0, 
 array arFilter = Array() 
);

The function returns active sections of an information block iblock_id.

Parameters

ParameterDescription
iblock_id The ID of an information block to search for sections.
section_id The ID of the parent section. To obtain the root sections of an information block, set the parameter section_id to 0.

Optional. By default (false), all records are returned without restrictions.
order Optional sort order. Array of the format Array(by1=>order1[, by2=>order2 [, ..]]) where by is the field for sorting. The field can have the following values:
  • sort - sort weight;
  • timestamp_x - modification date;
  • name - name;
  • id - section ID;
  • left_margin - applies the through sorting (see Remarks);
  • depth_level - section nesting level.
order is the sort order. Can be asc for ascending sorts or desc for descending.

Default value is Array("sort"=>"asc"). Full list of sorting fields and additional information can be found in CIBlockElement::GetList()
cnt Maximum number of the returned records. Optional. All records are returned by default.
arFilter Optional additional filter by fields in the form of Array("Filtered field"=>"Value", ...). The Filtered field can be the following:
  • ACTIVE - by the active state  (Y|N);
  • GLOBAL_ACTIVE - by the active state with respect to the active state of parent sections (Y|N);
  • NAME - by name (wildcards [%_] allowed);
  • CODE - by mnemonic code (wildcards [%_] allowed);
  • EXTERNAL_ID - by the external ID (wildcards [%_] allowed);
  • IBLOCK_ID - by the information block ID;
  • DEPTH_LEVEL - by nesting level;
  • SECTION_ID - by parent section;
  • LEFT_MARGIN, RIGHT_MARGIN - by left or right margin (see Remarks);
  • ID - by the ID;
  • PROPERTY - by values of the properties of the child elements; PROPERTY is an array of the format Array("property ID"=>"value", ...).
All the filter fields may have the conditions specified before the name.

By default, no additional filtering applied.

Full list of sorting fields and additional information can be found in CIBlockElement::GetList()

Return Values

The function returns an instance of CDBResult containing the active sections, i.e. those of active information blocks and contained in active parent sections.

Remarks

  1. To facilitate handling the function return values, you can use the method CDBResult::GetNext() returning an array of the information block element fields. All fields returned by this method are HTML compliant and safe. If the result is empty or the end of collection is reached, false is returned.
  2. The sorting field left_margin (the so-called "through sorting") is calculated based on the field sort, nesting level and the parent level sort weight. The difference between sort and left_margin is that the sort is defined by the user to sort sections within a single parent section, while the left_margin is calculated automatically and is used for sorting within the whole information block.

See Also

  • Fields of information block sections
  • Example

    <?
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
    
    $APPLICATION->SetTitle("Catalog");
    
    if(CModule::IncludeModule("iblock"))
    {
       // if $ID is not specified or is not a number, it is assumed to be 0;
       // select root sections
       $ID = IntVal($_GET['ID']);
       // select sections from the information block $BID and section $ID
       $items = GetIBlockSectionList($_GET['BID'], $ID, 
                                     Array("sort"=>"asc"), 10);
       while($arItem = $items->GetNext())
       {
          echo '<a href="catalog.php?bid='.urlencode($_get['bid']).
               '&ID='.$arItem['ID'].'">'.$arItem["NAME"].'</a><br>';
          echo $arItem["DESCRIPTION"]."<br>";
       }
    }
    else
       ShowError("The module is not installed");
    
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
    ?>
    
    © «Bitrix24», 2001-2024