/** * Рекурсивное преобразование ключей массива в нижний регистр. * В шаблонизаторе Twig все массивы и переменные находятся в нижнем регистре. * * @param array $arItems Ассоциированный массив неограниченной глубины * @param int $index Глубина массива (По умолчанию равен "0") * * @example index.php 43 1 Пример использования */ function TwigKeysStrtolower(&$arItems, $index = 0) { if (is_array($arItems)) { foreach ($arItems as $key => &$val) { if (is_array($val)) { TwigKeysStrtolower($val, $key); } else { $arItems[mb_strtolower($key)] = $val; unset($arItems[mb_strtoupper($key)]); } } } }
switch ($type) { case 'article': /** @var string Название шаблона */ $tpl = 'edit-article.html'; if ($id_item > 0) { if (isset($_POST)) { $isUpdate = $db->Update('articles', $_POST, array('ID' => $id_item)); } $query = $db->Query('SELECT * FROM `articles` WHERE `ID` = ' . $id_item); if ($query->num_rows == 1) { if ($result = $query->fetch_assoc()) { $content['article']['detail'] = $result; } } } else { if (isset($_POST)) { $db->Insert('articles', $_POST); } } break; default: # code... break; } } $query = $db->Query('SELECT * FROM `articles` ORDER BY `DATE_CREATE` DESC'); while ($result = $query->fetch_assoc()) { $content['article']['list'][] = $result; } TwigKeysStrtolower($content); echo $twig->render(empty($tpl) ? 'dashboard.html' : $tpl, array('app' => $arApp, 'content' => $content));