0

我正在使用递归函数在树中转换我的菜单。我从数据库中得到的数组是:

array ( 
  [0] => stdClass Object ( 
    [nav_group_id] => 1 
    [entity_id] => 1 
    [parent] => 0 
    [name] => Meter Reading 
    [link] => # ) 
  [1] => stdClass Object ( 
    [nav_group_id] => 1 
    [entity_id] => 2 
    [parent] => 0 
    [name] => Parameterization 
    [link] => # ) 
  [2] => stdClass Object ( 
    [nav_group_id] => 1 
    [entity_id] => 3 
    [parent] => 0 
    [name] => View Reports 
    [link] => # ) 
  [3] => stdClass Object ( 
    [nav_group_id] => 1 
    [entity_id] => 4 
    [parent] => 0 
    [name] => Management & Control 
    [link] => # ) 
  [4] => stdClass Object ( 
    [nav_group_id] => 1 
    [entity_id] => 5 
    [parent] => 1 
    [name] => Billing Data 
    [link] => # ) 
  [5] => stdClass Object ( 
    [nav_group_id] => 1 
    [entity_id] => 6 
    [parent] => 1 
    [name] => MDI Billing Data
    [link] => # )

我通过将上述数组传递给该函数来调用递归函数:

$this->parseAndPrintTree('0',$navigation_all);
//die();   (issue here)

现在,如果我die();在此功能之后使用它会显示正确的菜单,并且如果不使用die();页面将无法加载并给出此错误:

内容编码错误您尝试查看的页面无法显示,因为它使用了无效或不受支持的压缩形式。”

...并且没有显示输出。这是我的递归函数:

function parseAndPrintTree($root, $tree) 
{
    $return = array();
    if(!is_null($tree) && count($tree) > 0) 
    {
        echo '<ul>';
        foreach($tree as $child => $parent) 
        {
            if($parent->parent == $root) 
            {                    
                unset($tree[$child]);
                echo '<li>'.$parent->name;
                $this->parseAndPrintTree($parent->entity_id, $tree);
                echo '</li>';
            }
        }
        echo '</ul>';
    }
}
4

2 回答 2

0

因为我似乎正在做某事,所以我会将其发布为答案。

When you have gzip compression enabled, you cannot output anything to the browser before the compression functions have a chance to output, which Codeigniter automatically does near the end of its execution stack. In your recursion function you have an echo which is what is doing this output.

The best way to fix this is to convert this function in to a helper function, and then put the call to this function inside a view file rather than a controller or library which is where I assume it is now.

于 2012-07-19T13:22:47.637 回答
0

For posterity's sake, I ran into this error message while working on Code 2.1.0 in Firefox, and I landed here. My problem was that my code had an error or warning which was generated in a sub view. Because my /application/config/config.php file had this line

$config['compress_output'] = TRUE;

I received the same error message as the question author. I changed that line

$config['compress_output'] = FALSE;

Then, I was able to see the real error I was dealing with. Hope this helps someone!

于 2013-02-02T01:00:40.700 回答