Views: 3083
Last Modified: 19.05.2022
Complex components have an in-built SEF generating function. These components always have an input parameter SEF_MODE
, which can accept values Y
and N
. When parameter SEF_MODE
equals N
, the component operates with actual links and passes all parameters using query's standard HTTP parameters. For example:
/fld/cat.php?IBLOCK_ID=12&SECTION_ID=371
When the parameter SEF_MODE
equals Y
, the component generates and processes links based on templates. For example, it can recognize and process the link as follows:
/catalog/section/371.php?IBLOCK_ID=12, even if the parameter is located in the file
/fld/cat.php
.
When the parameter SEF_MODE
equals Y
, the component must have the parameter SEF_FOLDER
, containing path to folder handled by the component. This path can may match with actual path and may not. For example, the component bitrix:catalog, connected in the file /fld/cat.php
can have the specified parameters SEF_MODE = Y
and SEF_FOLDER=/catalog/
. Then component will respond to queries at the path /catalog/...
. By default, editor must set a current actual path to edited file.
Complex component that can operate in SEF mode, must have a defined set of default path templates. For example, complex component bitrix:catalog can have a defined array as follows:
$arDefaultUrlTemplatesSEF = array(
"list" => "index.php",
"section" => "section.php?IBLOCK_ID=#IBLOCK_ID#&SECTION_ID=#SECTION_ID#",
"element" => "element.php?ELEMENT_ID=#ELEMENT_ID#"
);
These path templates can be redefined using the complex component input parameter SEF_URL_TEMPLATES
, containing new array with all path templates or their segments.
Upon saving a page in editor with the component, operating in SEF mode, the system creates or updates an urlrewrite
record. For example, urlrewrite system creates or updates the record type when saving the file /fld/cat.php
, containing the component bitrix:catalog, switched to SEF mode with the parameter SEF_FOLDER=/catalog/
:
array(
"CONDITION" => "#^/catalog/#",
"ID" => "bitrix:catalog",
"PATH" => "/fld/cat.php"
),
-
CONDITION
writes the value of parameter SEF_FOLDER
, framed with symbols "#^" and "#";
- The
ID
writes the name of component;
- The
PATH
writes the actual path to file to be saved.
When the record with such PATH
and ID
already exist, it's updated, if doesn't - it's added.
Upon querying a non-existent page, the urlrewrite run-time searches a corresponding record by CONDITION
and forwards control to the PATH
page.
Based on template paths, component at the PATH
page identifies the requested page and restores variables, hidden within the path.
Attention! Mandatory requirement to the set of template paths for this component: each path template must be unique without accounting parameters and variables. This requirement must be checked upon saving a page in visual editor.
That is, set of path templates
"section" => "section/#SECTION_ID#.php?IBLOCK_ID=#IBLOCK_ID#",
"element" => "element/#ELEMENT_ID#.php"
is permissible and set of paths
"section" => "#SECTION_ID#.php?IBLOCK_ID=#IBLOCK_ID#",
"element" => "#ELEMENT_ID#.php"
is not permitted.