S
S
Stanislav2017-03-06 15:04:27
Yii
Stanislav, 2017-03-06 15:04:27

Module 'memcache' already loaded on hosting?

The site throws out this message when visiting one of the pages. Before that everything was ok.
After deleting the cache in runtime / cache - the page is loaded for the first time, and this message pops up the second time. Should I kick the hoster or is it a problem on my part?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Axian Ltd., 2017-03-06
@Stasgar

Hoster probably, I got this after updating php. For some reason, it stuck the module twice.

V
Vitaliy Orlov, 2017-12-01
@gachkydxvbgd

In short:
- you start to form a tree from parents
- at each iteration you check if there are children with parent_id = parent ID
- you repeat until you run out of descendants The
easiest way is to implement recursion, here is an example

<?php

$items = [
    ['ID'=>35, 'menu_item_parent'=>0],
        ['ID'=>38, 'menu_item_parent'=>35],
        ['ID'=>36, 'menu_item_parent'=>35],
            ['ID'=>39, 'menu_item_parent'=>36],
                ['ID'=>40, 'menu_item_parent'=>39],
                ['ID'=>41, 'menu_item_parent'=>39],
    ['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);

result
Array
(
    [0] => Array
        (
            [ID] => 35
            [menu_item_parent] => 0
            [subitems] => Array
                (
                    [0] => Array
                        (
                            [ID] => 38
                            [menu_item_parent] => 35
                            [subitems] => Array
                                (
                                )

                        )

                    [1] => Array
                        (
                            [ID] => 36
                            [menu_item_parent] => 35
                            [subitems] => Array
                                (
                                    [0] => Array
                                        (
                                            [ID] => 39
                                            [menu_item_parent] => 36
                                            [subitems] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [ID] => 40
                                                            [menu_item_parent] => 39
                                                            [subitems] => Array
                                                                (
                                                                )

                                                        )

                                                    [1] => Array
                                                        (
                                                            [ID] => 41
                                                            [menu_item_parent] => 39
                                                            [subitems] => Array
                                                                (
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [1] => Array
        (
            [ID] => 37
            [menu_item_parent] => 0
            [subitems] => Array
                (
                )

        )

)
====================================================
35
-- 38
-- 36
---- 39
------ 40
------ 41
37

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question