/* * @author Administrator * @filename Menu.php * @date 2009-11-21 */ class Side_Menu_Core { protected $type; //guest, user, admin protected $items; private function __construct($type = null) { $this->type = $type; /* * pobranie z bazy stałych elementów to chyba dobre miejsce */ } if (self::$instance === NULL) self::$instance = new Side_Menu($type); self::$instance->type = $type; return self::$instance; } public function add(Menu_item $item){ $this->items[$item->id] = $item; if($item->parent > 0){ $this->items[$item->parent]->append($item->id); } } public function get($id){ return $this->items[$id]; } public function set_active($id){ if($id == 0){ return; } $item = $this->get($id); $item->active = TRUE; $this->set_active($item->parent); } public function __toString() { return $this->render(); } public function render(){ $output = '<ul>'; foreach($this->items as $item){ $output .= $item->render(); } $output .= '</ul>'; return $output; } public function get_parents(){ } public function get_children($id_parent){ } } class Menu_item { public $id = 0; public $parent = 0; public $children; public $title; public $link; public $active; public function __construct($setting) { $this->parent = $setting['parent']; } $this->title = $setting['title']; $this->link = $setting['link']; $this->id = $setting['id']; } public function append($id){ $this->children[] = $id; } public function render(){ $output = ''; return '<li>'.$this->title.'</li>'; } $output .= '<li>'.$this->title.'</li>'; $output .= '<ul>'; foreach($this->children as $child){ $output .= Side_Menu_Core::instance()->get($child)->render(); } $output .= '</ul>'; } return $output; } public function render_without_children(){ return $output = '<li>'.$this->title.'</li>'; } } ?>
Mam problem, gdy oznaczę jeden wpis jako child, on dalej wyświetla się jako parent. Probowałem różnymi ifami, że parent = 0 empty(child), ale dalej wyświetla się drugi raz w głównej linii.
Przy okazji prosiłbym o uwagi to tej klasy.