<?php
$items = [
(object) ['ID'=>35, 'menu_item_parent'=>0],
(object) ['ID'=>38, 'menu_item_parent'=>35],
(object) ['ID'=>36, 'menu_item_parent'=>35],
(object) ['ID'=>39, 'menu_item_parent'=>36],
(object) ['ID'=>40, 'menu_item_parent'=>39],
(object) ['ID'=>41, 'menu_item_parent'=>39],
(object) ['ID'=>37, 'menu_item_parent'=>0],
];
function find_childrens($items, $parentItem) {
$ret = [];
foreach($items as $item) {
if ($item->menu_item_parent == $parentItem->ID) {
$treeItem = $item;
$treeItem->subitems = find_childrens($items, $item);
$ret[] = $treeItem;
}
}
return $ret;
}
$tree = [];
foreach($items as $item) {
if ($item->menu_item_parent == 0) {
$treeItem = $item;
$treeItem->subitems = find_childrens($items, $item);
$tree[] = $treeItem;
}
}
echo '<pre>';
print_r($tree);
echo '</pre>';
echo '<hr>';
function printer($treeItem, $level) {
if ($level) echo str_repeat('--', $level);
echo $treeItem->ID.'<br>';
if ($treeItem->subitems) {
foreach($treeItem->subitems as $subItem) {
printer($subItem, $level+1);
}
}
}
foreach($tree as $treeItem) printer($treeItem, 0);
$('#pjax-id')
.on('pjax:click', function(event) {
})
.on('pjax:success', function(event) {
})
.on('pjax:error', function (event) {
alert('Failed to load the page');
event.preventDefault();
});
get_footer($name) - добавляет шаблон footer.php из директориии, в которой расположены шаблоны текущей темы. Если задан параметр name, то будет добавлен шаблон подвала с именем footer-{name}.php.
use modules\datebase\connection;
public function actionIndex(){
$foo = 'abc';
$bar = 'def';
return $this->render('@views/a', [
'foo' => $foo,
'bar' => $bar,
]);
}
$this->render('b', [
'foo' => $foo,
'bar' => $bar,
]);
$this->render('c', [
'foo' => $foo,
'bar' => $bar,
]);
print_r($foo);
print_r($bar);