Last active
December 23, 2020 15:02
-
-
Save iTeeLion/e92f6aea3d06799b9a95878f7bdced34 to your computer and use it in GitHub Desktop.
PHP snippets for bitrix / Примеры самых используемых конструкций в bitrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Bitrix init (paths to header/prolog/footer) | |
*/ | |
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/header.php'); | |
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); | |
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/footer.php'); | |
/* | |
* Include module | |
*/ | |
CModule::IncludeModule('crm')); | |
CModule::IncludeModule('sale')); | |
CModule::IncludeModule('iblock')); | |
CModule::IncludeModule('catalog')); | |
/* | |
* Header show methods | |
*/ | |
$GLOBALS['APPLICATION']->ShowTitle(); | |
$GLOBALS['APPLICATION']->ShowHead(); | |
$GLOBALS['APPLICATION']->ShowMeta('keywords'); | |
$GLOBALS['APPLICATION']->ShowMeta('description'); | |
$GLOBALS['APPLICATION']->ShowCSS(); | |
$GLOBALS['APPLICATION']->ShowHeadStrings(); | |
$GLOBALS['APPLICATION']->ShowHeadScripts(); | |
$GLOBALS['APPLICATION']->ShowPanel(); | |
$GLOBALS['APPLICATION']->RestartBuffer(); | |
/* | |
* Add JS and CSS assets | |
*/ | |
$GLOBALS['APPLICATION']->SetAdditionalCss('/link/to/css'); | |
$GLOBALS['APPLICATION']->SetAdditionalJS('/link/to/js'); | |
/* | |
* User | |
*/ | |
// Get curent user | |
$arUser = \CUser::GetByID($GLOBALS['USER']->GetID())->Fetch(); | |
// Get current user groups | |
$GLOBALS['USER']->GetUserGroupArray(); | |
// GetList | |
$by = 'ID'; | |
$order = 'ASC'; | |
$arFilter = ['ACTIVE' => 'Y']; | |
$arParams = []; | |
$dbRes = \CUser::GetList($by, $order, $arFilter, $arParams); | |
while ($user = $dbRes->GetNext()) { | |
echo '<pre>'; var_dump($item); echo '</pre>'; | |
} | |
/* | |
* IBlock | |
*/ | |
// GetList | |
$arOrder = ['SORT' => 'ASC']; | |
$arFilter = ['IBLOCK_ID' => '', 'ACTIVE' => 'Y']; | |
$arGroupBy = false; | |
$arNav = false; | |
$arSelect = ['ID', 'IBLOCK_ID', 'NAME', 'PROPERTY_*']; | |
$dbRes = \CIBlockElement::GetList($arOrder, $arFilter, $arGroupBy, $arNav, $arSelect); | |
while ($item = $dbRes->GetNext()) { | |
echo '<pre>'; var_dump($item); echo '</pre>'; | |
} | |
while ($ob = $dbRes->GetNextElement()) { | |
$item = $ob->GetFields(); | |
$item['PROPERTIES'] = $ob->GetProperties(); | |
} | |
// Set permissions | |
$ElementRights = new \CIBlockElementRights($IBLOCK_ID, $ELEMENT_ID); | |
$arPermissions = $ElementRights->GetRights(); | |
$arPermissions['n0'] = [ | |
'GROUP_CODE' => 'U1', | |
'TASK_ID' => 51, | |
]; | |
$ElementRights->SetRights($arPermissions); | |
/* | |
* CEvent | |
*/ | |
// Send email | |
\CEvent::SendImmediate($event, $lid, $arFields, $Duplicate = 'Y', $message_id=''); | |
/* | |
* CFile | |
*/ | |
// Save file | |
$fileId = \CFile::SaveFile($_FILES['somefile'], 'FolderName_InUploads'); | |
// Resize image | |
\CFile::ResizeImageGet($pictureId, ['width' => 300, 'height' => 9999], BX_RESIZE_IMAGE_PROPORTIONAL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Примеры самого необходимого кода в bitrix
Как подключить модуль апи битрикс без хедера
Как подключить хедер битрикс
Как подключить футер битрикс
Как подключить модуль в битрикс
Как вывести тайтл в бирикс
Как вывести хедер битрикс
Как вывести все css и js файлы подключенный в битрикс
Как вывести мета тег в битрикс
Как вывести панель админа в битрикс
Как очистить содержимое страницы перед выводом
Как подключить css файл к шаблону битрикс
Как подключить js файл к шаблону битрикс
Как получить user fileld, как получить uf свойство в битрикс
Как отправить email в битрикс