The last notes
All English-language materials have been translated fully automatically using the Google service
Quite often I am asked to make a fairly voluminous page with content located in the infoblock. Where sections are sections of the page, and section items are section list items or settings. Here is the code that I use for most of these cases
if (CModule :: IncludeModule ("iblock")) {
$ cntIBLOCK_List = 50;
$ cache = new CPHPCache ();
$ cache_time = 3600 * 12 * 7; // cache for a week
$ cache_id = 'preferences'. $ cntIBLOCK_List;
$ cache_path = 'preferences';
if ($ cache_time> 0 && $ cache-> InitCache ($ cache_time, $ cache_id, $ cache_path))
{
$ res = $ cache-> GetVars ();
if (is_array ($ res ["preferences"]) && (count ($ res ["preferences"])> 0)) {
$ preferences = $ res ["preferences"];
}
$ preferences ['CACHE'] = 'true';
}
if (! is_array ($ preferences))
{
$ preferences ['CACHE'] = 'false';
$ arFilter = Array ('IBLOCK_TYPE' => 'content', 'IBLOCK_ID' => $ cntIBLOCK_List, 'GLOBAL_ACTIVE' => 'Y');
$ arSelect = array ("ID", "IBLOCK_ID", "NAME", "CODE", "UF_ *");
$ rsCityList = CIBlockSection :: GetList (Array (), $ arFilter, true, $ arSelect);
while ($ item = $ rsCityList-> GetNext ()) {
$ preferences [$ item ['ID']] = $ item;
$ arSort = array ('SORT' => 'ASC', 'ID' => 'DESC');
$ arFilter = array ('ACTIVE' => 'Y', 'IBLOCK_ID' => $ cntIBLOCK_List, 'IBLOCK_SECTION_ID' => $ item ['ID']);
$ arSelect = array ('ID', 'NAME', 'DETAIL_PAGE_URL', 'PREVIEW_TEXT');
$ res = CIBlockElement :: getList ($ arSort, $ arFilter, false, array (), $ arSelect);
while ($ row = $ res-> fetch ()) {
$ preferences [$ item ['ID']] ['ITEMS'] [] = $ row;
}
}
//////////// end cache /////////
if ($ cache_time> 0)
{
$ cache-> StartDataCache ($ cache_time, $ cache_id, $ cache_path);
$ cache-> EndDataCache (array ("preferences" => $ preferences));
}
}
}
Comments