Pergunta

I am using a recursion function to convert my menus in a tree. The array I got from the database is:

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] => # )

I am calling a recursive function by passing the above mentioned array to this function:

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

Now if I use die(); after this function it shows the correct menu, and if don't use die(); the page fails to load and gives this error:

Content Encoding Error The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression."

...and shows no output. Here is my recursive function:

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>';
    }
}
Foi útil?

Solução

As I seem to be on to something I'll post this as an answer.

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.

Outras dicas

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!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top