Views: 10477
Last Modified: 10.10.2012
The composite components have a built-in SEF URL generator. These components can take the SEF_MODE input parameter that can be Y or N. If SEF_MODE is N, the component works with physical links and passes all parameters via HTTP standard request parameters. For example,
/fld/cat.php?IBLOCK_ID=12&SECTION_ID=371.
If SEF_MODE is Y, the component generates and processes links using templates. For example, it can process the link
/catalog/section/371.php?IBLOCK_ID=12,
even if the component is in the /fld/cat.php file.
If SEF_MODE is Y, the component must have the SEF_FOLDER parameter that contains the path to the component working directory. This path can be the same as the physical path or it can be different.
For example, the bitrix:catalog component in a file /fld/cat.php can have the parameters SEF_MODE = Y and SEF_FOLDER=/catalog/. The component will respond to requests having /catalog/... in URL. By default, the editor must set the current physical path of a current file.
Composite SEF URL enabled components must be assigned a set of default path templates. For example, the bitrix:catalog component can define the following array:
$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 input parameter SEF_URL_TEMPLATES containing a new array of all or some path templates.
When saving a page having a component that operates in SEF mode, the editor creates or updates a URL Rewrite system record. For example, when saving the file /fld/cat.php containing the bitrix:catalog SEF mode component whose parameter is SEF_FOLDER=/catalog/, the following record is created or updated:
array(
"CONDITION" => "#^/catalog/#",
"ID" => "bitrix:catalog",
"PATH" => "/fld/cat.php"
),
- CONDITION contains the value of SEF_FOLDER enclosed in #^ and #;
- ID is set to the component name;
- PATH contains the physical path to the file to which the component is added.
If a record with such PATH and ID already exists, it is updated; otherwise, it is created.
At runtime, a request for a non-existing page starts the URL Rewrite mechanism that looks up the rewrite table by CONDITION and passes control over to a page specified in PATH. The component on the PATH page determines the requested page by the path templates and restores the variables on the path.
Note! Each path template must be unique in its static part. You must carefully check the uniqueness in the visual editor. The following examples illustrate this requirement.
The templates:
"section" => "section/#SECTION_ID#.php?IBLOCK_ID=#IBLOCK_ID#",
"element" => "element/#ELEMENT_ID#.php"
are valid because the static parts section and element are different.
The templates:
"section" => "#SECTION_ID#.php?IBLOCK_ID=#IBLOCK_ID#",
"element" => "#ELEMENT_ID#.php"
are invalid because there are no static parts that are different.
As you can see, file extensions, parameters and macros are not treated as static parts.