A
A
Andrey Eskov2018-07-06 14:47:57
1C-Bitrix
Andrey Eskov, 2018-07-06 14:47:57

Complex component development, how to transfer CNC data?

Good afternoon. Dear tell me, I can not create the structure of a complex component.
There are 2 template files list and element
Now it is necessary to resolve their connection in the components file with and without CNC enabled.
Here is my code from component

$arDefaultUrlTemplates404 = array(
    "list" => "",
    "element" => "#MANUFACTURER_ID#/"
);

$arDefaultVariableAliases404 = array();
$arDefaultVariableAliases = array();
$arComponentVariables = array("MANUFACTURER_ID");

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["MANUFACTURER_ID"]) > 0)
        $componentPage = "element";
    else
        $componentPage = "list";

}

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

$this->IncludeComponentTemplate($componentPage);

If the CNC is disabled, then everything is fine, if the parameter is passed (/list/?MANUFACTURER_ID=2), then the element template file is connected, but if I turn on the CNC and pass /list/2/ for example, I see 404. (No logic and components in there are no list and element files!)
What am I doing wrong? How can I indicate that if I pass a parameter, then I mean exactly MANUFACTURER_ID and that the element template file needs to be included?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kudis, 2018-07-06
@taurus2790

For CNC, you need to edit urlrewrite.php
for example:

array(
        "CONDITION" => "#^/catalog/(\\d+)/(\\d+)/id(\\d+)/[^\/]*$#",
        "RULE" => "SECTION_ID=\$1&SUBSECTION_ID=\$2&ELEMENT_ID=\$3",
        "ID" => "galament:shop",
        "PATH" => "/catalog/index.php",
    ),

will catch all requests like /catalog/123/123/id123/
and put them into variables SECTION_ID=\$1&SUBSECTION_ID=\$2&ELEMENT_ID=\$3
and you need to include 'element' in a complex component, for example, as it is done in Bitrix catalog
if(isset($arVariables["action"]) && in_array($arVariables["action"], $arCompareCommands))
    $componentPage = "compare";
  elseif(isset($arVariables["ELEMENT_ID"]) && intval($arVariables["ELEMENT_ID"]) > 0)
    $componentPage = "element";
  elseif(isset($arVariables["ELEMENT_CODE"]) && strlen($arVariables["ELEMENT_CODE"]) > 0)
    $componentPage = "element";
  elseif(isset($arVariables["SECTION_ID"]) && intval($arVariables["SECTION_ID"]) > 0)
    $componentPage = "section";
  elseif(isset($arVariables["SECTION_CODE"]) && strlen($arVariables["SECTION_CODE"]) > 0)
    $componentPage = "section";
  elseif(isset($_REQUEST["q"]))
    $componentPage = "search";
  else
    $componentPage = "sections";
   $this->IncludeComponentTemplate($componentPage);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question