/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Get Menu * * Builds a menu based on what the current user has access to. * * @return string */ public function get_menu() { // Load the available paths from the database. $crm = url::is_admin() ? '1' : '0'; $sql = 'SELECT p.id, p.parent_id, p.path, p.text FROM paths AS p, path_users AS u WHERE u.user_id='.$this->user->id.' AND u.path_id=p.id ORDER BY p.parent_id ASC, p.display ASC'; $query = $this->db->query($sql); // Loop through the results and build a new array. foreach ($query as $row) { 'path' => $row->path, 'text' => $row->text ); // Parent page? if ($row->parent_id == 0) { $pages[$row->id] = $data; } else { $pages[$row->parent_id]['children'][] = $data; } } // Build the output $output = ''; foreach ($pages as $page) { $output .= '<ul><li><a href="'.$page['path'].'">'.$page['text'].'</a>'; // Build children. if ($total > 0) { $output .= '<ul>'; for ($i = 0; $i < $total; ++$i) { $output .= '<li><a href="'.$page['children'][$i]['path'].'">'.$page['children'][$i]['text'].'</a></li>'; } $output .= '</ul>'; } $output .= '<li></ul>'; } return $output; }