Bitrix Site Manager

CComponentEngine::InitComponentVariables

void
InitComponentVariables(
 string componentPage ,
 array arComponentVariables ,
 array arVariableAliases ,
 array & arVariables
);

The method is used with aliases of variables in compound components (also with human-friendly URL's). This method restores original variable values from $_REQUEST based on their aliases.

Parameters

Parameter Description
componentPage For human-friendly URL's: code of the path template that was obtained using CComponentEngine::ParseComponentPath. For non human friendly URL's, this parameters must be false.
arComponentVariables An array of variable names which the component may obtain from the query. This parameter has the following format: array("variable name 1", "variable name 2", ...).
arVariableAliases An array of variable aliases.

The parameter has the following format for human-friendly URL's:
array(
    "code of the path template 1" => array(
        "variable name 11" => "variable alias 11",
        "variable name 12" => "variable alias 12",
        * * *
    ), 
    "code of the path template 2" => array(
        "variable name 21" => "variable alias 21",
        "variable name 22" => "variable alias 22",
        * * *
    ),
    * * *
)    
For non human friendly URL's:
array(
    "variable name" => "variable alias",
    * * *
)    
arVariables A variable in which all restored variables are returned.

Example


// For human friendly URL's

// Store values of original variables in this variable
$arVariables = array();

// Build an array of path templates from such array...
// "by default" $arDefaultUrlTemplates404
// and an array passed in $arParams["SEF_URL_TEMPLATES"]
$arUrlTemplates = 
    CComponentEngine::MakeComponentUrlTemplates($arDefaultUrlTemplates404, 
                                                $arParams["SEF_URL_TEMPLATES"]);

// Build an array of variable aliases from such array...
// "by default" $arDefaultVariableAliases404
// and an array passed in $arParams["VARIABLE_ALIASES"]
$arVariableAliases = 
    CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases404, 
                                                   $arParams["VARIABLE_ALIASES"]);

// Define the template code
// to which the current queried page corresponds $componentPage = CComponentEngine::ParseComponentPath( $arParams["SEF_FOLDER"], $arUrlTemplates, $arVariables ); // If the requested page does not correspond to any template // specify the contents explicitly if (StrLen($componentPage) <= 0) $componentPage = "list"; // Now that we have the code of the path template and variables // that were passed as the path to a requested // page, register in $arVariables // Restore the variables that were passed in the query parameters // and append them to $arVariables CComponentEngine::InitComponentVariables($componentPage, $arComponentVariables, $arVariableAliases, $arVariables); // Now, based on the code of the path template $componentPage // and original variables $arVariables // define which page of the component template should be displayed if ($componentPage == "element") $componentPage = "element"; elseif ($componentPage == "section1" || $componentPage == "section2") $componentPage = "section"; else $componentPage = "list"; $this->IncludeComponentTemplate( array( "FOLDER" => $arParams["SEF_FOLDER"], "URL_TEMPLATES" => $arUrlTemplates, "VARIABLES" => $arVariables, "ALIASES" => $arVariableAliases ), $componentPage );
// For non human friendly URL's

// Store values of original variables in this variable
$arVariables = array(); // Build an array of variable aliases from such array... // "by default" $arDefaultVariableAliases // and an array passed in $arParams["VARIABLE_ALIASES"] $arVariableAliases = CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases, $arParams["VARIABLE_ALIASES"]); // Restore the variables that were passed in the query parameters // and append them to $arVariables CComponentEngine::InitComponentVariables(False, $arComponentVariables, $arVariableAliases, $arVariables); // Now, based on the original variables $arVariables // define which page of the component template should be displayed $componentPage = ""; if (IntVal($arVariables["ELEMENT_ID"]) > 0) $componentPage = "element"; elseif (IntVal($arVariables["IBLOCK_ID"]) > 0 || IntVal($arVariables["SECTION"]) > 0) $componentPage = "section"; else $componentPage = "list"; $this->IncludeComponentTemplate( array( "VARIABLES" => $arVariables, "ALIASES" => $arVariableAliases ), $componentPage );

See Also

  • Compound component structure
  • Input parameter aliases
  • CComponentEngine::MakeComponentVariableAliases
  • CComponentEngine::MakeComponentUrlTemplates