Bitrix Site Manager

Structure of compound components

Complex components are used to create site sections (forum, catalog etc.); they connect simple components to display information. In fact, complex components are controllers that manage simple components. The complex component takes an HTTP request, defines the page to be displayed, and connects the template of this page.

The following code shows an example of a complex component.

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?><?

$arDefaultUrlTemplates404 = array(
   "list" => "index.php",
   "element" => "#ELEMENT_ID#.php"
);

$arDefaultVariableAliases404 = array();

$arDefaultVariableAliases = array();

$arComponentVariables = array("IBLOCK_ID", "ELEMENT_ID");


$SEF_FOLDER = "";
$arUrlTemplates = array();

if ($arParams["SEF_MODE"] == "Y")
{
   $arVariables = array();

    $arUrlTemplates = 
        CComponentEngine::MakeComponentUrlTemplates($arDefaultUrlTemplates404, 
                                                    $arParams["SEF_URL_TEMPLATES"]);
    $arVariableAliases = 
        CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases404, 
                                                       $arParams["VARIABLE_ALIASES"]);

   $componentPage = CComponentEngine::ParseComponentPath(
      $arParams["SEF_FOLDER"],
      $arUrlTemplates,
      $arVariables
   );

   if (StrLen($componentPage) <= 0)
      $componentPage = "list";

   CComponentEngine::InitComponentVariables($componentPage, 
                                            $arComponentVariables, 
                                            $arVariableAliases, 
                                            $arVariables);

   $SEF_FOLDER = $arParams["SEF_FOLDER"];
}
else
{
   $arVariables = array();

    $arVariableAliases = 
       CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases, 
                                                      $arParams["VARIABLE_ALIASES"]);
    CComponentEngine::InitComponentVariables(false, 
                                             $arComponentVariables, 
                                             $arVariableAliases, $arVariables);

   $componentPage = "";
   if (IntVal($arVariables["ELEMENT_ID"]) > 0)
      $componentPage = "element";
   else
      $componentPage = "list";

}

$arResult = array(
   "FOLDER" => $SEF_FOLDER,
   "URL_TEMPLATES" => $arUrlTemplates,
   "VARIABLES" => $arVariables,
   "ALIASES" => $arVariableAliases
);

$this->IncludeComponentTemplate($componentPage);
?>

First of all, the following arrays are defined:

The predefined input parameter SEF_MODE can be either or N. If $arParams["SEF_MODE"] is Y, the component functions in the human friendly mode, otherwise - not.

The predefined input parameter SEF_FOLDER is effective if only the component is in the human friendly mode. In this case, it contains the component working directory. The path can be virtual (i.e. it may not exist). For example, the above component resides in /fld/n.php and functions in the human friendly mode. Let SEF_FOLDER be /company/news/. In this case, the component will be available at /company/news/index.php, /company/news/25.php etc.

The following Methods are used to determine the correct page to display and to restore the real component variables from aliases.

In the human friendly mode, the component takes the path template ID and the HTTP request parameters, and determines the page to be displayed. Then, it passes the page name in the following call:

$this->IncludeComponentTemplate($componentPage);

On its pages, the compound component activates simple components and passes required parameters to them. For example, the "element" page of the sample component template (/templates/.default/list.php) can be he following:

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<?$APPLICATION->IncludeComponent(
   "bitrix:news.detail",
   "",
   Array(
      "IBLOCK_ID" => $arParams["IBLOCK_ID"],
      "ELEMENT_ID" => $arResult["VARIABLES"]["ELEMENT_ID"],
      "SECTION_ID" => $arResult["VARIABLES"]["SECTION_ID"],
      "CACHE_TIME" => $arParams["CACHE_TIME"],
   ),
   $component
);?>

The last parameter ($component) is an object containing the current component. This gives the component a chance to be notified that it is connected from within a compound component, and use the compound component resources etc.