Views: 14084
Last Modified: 19.09.2014
The file component_epilog.phpis a tool to modify the component operation data when caching is activated. It should be created by the developer independently (available in version 9.0 and later).
Sequence of Work of the Component with the Files result_modifier.php and component_epilog.php:
This file is connected after the execution of the template. Similarly to style files, the parent component stores a list of epilogue files of all the templates of child components (possibly embedded) in its cache and (following cache hit) connects these files in the same order as they were executed without caching. Likewise, when invoking child components, the value $component
must be submitted to the template.
$arParams, $arResult are available in the file component_epilog.php, but these values are retrieved from the cache. A set of keys of the $arResult array to be cached is determined in the file component.php as follows:
$this->SetResultCacheKeys(array(
"ID",
"IBLOCK_TYPE_ID",
"LIST_PAGE_URL",
"NAV_CACHED_DATA",
"NAME",
"SECTION",
"ELEMENTS",
));
When developing your own components, always use this structure in order to limit the cache size to the data that are really necessary.
Note: The file
component_epilog.php may contain any code. You should only keep in mind that it will be executed with each hit whether cache is available or not. In versions of the main module earlier than 10.0 a copy of the
arResult array was submitted to the component template. Due to this, the modification of this array in the file
result_modifier.php did not give any results. The following code shall be located in the
result_modifier.php to permit making changes in the results of cached data retrieval:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
global $APPLICATION;
$cp = $this->__component; // component object
if (is_object($cp))
{
// we add two fields - MY_TITLE and IS_OBJECT to arResult of the component
$cp->arResult['MY_TITLE'] = 'My title';
$cp->arResult['IS_OBJECT'] = 'Y';
$cp->SetResultCacheKeys(array('MY_TITLE','IS_OBJECT'));
// we save them in copy of arResult used by the template
$arResult['MY_TITLE'] = $cp->arResult['MY_TITLE'];
$arResult['IS_OBJECT'] = $cp->arResult['IS_OBJECT'];
$APPLICATION->SetTitle($cp->arResult['MY_TITLE']); // will not work on each hit:
//will work only the first time, then everything will be retrieved from the cache and there will be no invocation of $APPLICATION->SetTitle()
//That is why the title is changed in the component_epilog which is executed on each hit.
}
?>
After that, the changes made to arResult and performed in the template will become available in component_epilog.php.
Example of the File component_epilog.php
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
global $APPLICATION;
if (isset($arResult['MY_TITLE']))
$APPLICATION->SetTitle($arResult['MY_TITLE']);
?>
Specifics of Use
The file component_epilog.php is connected immediately after the connection and execution of the template. Thus, if the component provides for a template connection and then the component code provides for other operations, they will be executed after the execution of the file component_epilog.php.
Accordingly, in case the changed data coincide in the component_epilog.php and in the component code after the template is connected, only the latest data will be displayed, i.e. those from the component code.
Example of Such Situation
Let us use the file component_epilog.php from the example above. The component code (file component.php) contains the following code:
<?
$this->IncludeComponentTemplate();
if($arParams["SET_TITLE"])
{
$APPLICATION->SetTitle($arResult["NAME"]);
}
?>
In this case, you will not obtain the desired result since the component data will be displayed instead of those from
component_epilog.php.
The file component_epilog.php contains the following:
- $arParams - parameters, read/change. Does not affect the homonymous component member.
- $arResult — result, read/change. Does not affect the homonymous component class member.
- $componentPath — path to the component folder from DOCUMENT_ROOT (e.g.,
/bitrix/components/bitrix/iblock.list
).
- $component — link to $this.
- $this — link to the currently invoked component (CBitrixComponent class object), all class methods may be used.
- $epilogFile — path to the file component_epilog.php from DOCUMENT_ROOT
- $templateName - component template name (e.g.: .default)
- $templateFile — path to the template file from DOCUMENT_ROOT (e.g.
/bitrix/components/bitrix/iblock.list/templates/.default/template.php
)
- $templateFolder — path to the template folder from DOCUMENT_ROOT (e.g.
/bitrix/components/bitrix/iblock.list/templates/.default
)
- $templateData — please note that this is the way to transfer data from template.php to the file component_epilog.php, and these data will be sent to the cache and become available in component_epilog.php with each hit/
- $APPLICATION, $USER, $DB — global variables.