PHP Classes

Tree as html

Recommend this page to a friend!

      Nested set  >  All threads  >  Tree as html  >  (Un) Subscribe thread alerts  
Subject:Tree as html
Summary:exception on last node at tree
Messages:1
Author:MIchail
Date:2013-07-08 09:12:07
 

  1. Tree as html   Reply   Report abuse  
Picture of MIchail MIchail - 2013-07-08 09:12:07
Thouse method throws exception on last node. i was write it like this
public function treeAsHtml() {
$tree = $this->getTree();
$html = "<ul>\n";
for ($i=0; $i<count($tree); $i++) {
$html .= "<li>" . $tree[$i][$this->name];
if(isset( $tree[$i+1] )) {
if ($tree[$i]['level'] < $tree[$i+1]['level']) {
$html .= "\n<ul>\n";
} elseif ($tree[$i]['level'] == $tree[$i+1]['level']) {
$html .= "</li>\n";
} else {
$diff = $tree[$i]['level'] - $tree[$i+1]['level'];
$html .= str_repeat("</li>\n</ul>\n", $diff) . "</li>\n";
}
} else {
$html .= str_repeat("</li>\n</ul>\n", $tree[$i]['level']) . "</li>\n";
}
}
$html .= "</ul>\n";
return $html;
}