Login   Register  
PHP Classes
elePHPant
Icontem

Tree as html

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      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  
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;
}