olimortimer/ci-nested-sets

looping forever in getSubTreeAsHTML

Opened this issue · 3 comments

The while loop is looping forever

    public function getSubTreeAsHTML($nodes, $fields = array()) {
        if(isset($nodes[0]) && !is_array($nodes[0])) {
            $nodes = array($nodes);
        }

        $retVal = '';
        foreach($nodes AS $node) {
            $tree_handle = $this->getTreePreorder($node);

            while($this->getTreeNext($tree_handle))
            {
                // print indentation
                $retVal .= (str_repeat(' ', $this->getTreeLevel($tree_handle)*4));

                // print requested fields
                $field = reset($fields);
                while($field){
                    $retVal .= $tree_handle['row'][$field] . "\n";
                    $field = next($fields);
                }
                $retVal .= "<br />\n";

            }

        }

        return $retVal;
    }

i think you forgot passing by reference

    public function getTreeNext(&$tree_handle) {

    }  

@khashabawy did the change the getTreeNext() fix your looping issue? If so, could you make the change and raise a pull request please?

passing by reference seams to fix the problem but i think the function should be rewritten to unset
another problem if i change the order of the root trees when you get the tree is not in the right order (it uses the insert order)
i modified getRootNodes to order by lft asc
i will come back with more feedback or code as i test the class