Welcome Guest, Not a member yet? Register   Sign In
Newbie trying to figure out a menu
#1

[eluser]carlhussey[/eluser]
Hey guys, I'm new to codeigniter and slowly figuring things out as I go along.

I have a template I'm building my site around and it has a menu structure in it that im trying to populate based on certain information.

Here is the layout of the menu.

Code:
<ul id="main-nav">  &lt;!-- Accordion Menu --&gt;
                
                <li>
                    <a Xref="home" class="nav-top-item no-submenu"> &lt;!-- Add the class "no-submenu" to menu items with no sub menu --&gt;
                        Dashboard
                    </a>      
                </li>
                
                <li>
                    <a Xref="#" class="nav-top-item current"> &lt;!-- Add the class "current" to current menu item --&gt;
                    News / Updates
                    </a>
                    <ul>
                         <li><a Xref="#">Whats Crackin'?</a></li>        
                        <li><a Xref="#">Reminders</a></li>
                        <li><a class="current" Xref="#">Calander of Events</a></li> &lt;!-- Add class "current" to sub menu items also --&gt;

                    </ul>
                </li>
                
                <li>
                    <a Xref="#" class="nav-top-item">
                        Schedule
                    </a>
                    <ul>
                        <li><a Xref="#">View Current Schedule</a></li>
                        <li><a Xref="#">View Past Schedules</a></li>
                        <li><a Xref="#">Request Time Off</a></li>
                    </ul>
                </li>

The part that im stuck on is the fact that the menu is shown in a certain way depending on the page they are on. There are main categories and then sub links in that category

If i were to click on News and Updates, then the class would be class="nav-top-item current"

Then, the sub link that is clicked on would contain <a class="current">

Basically, the class in the view changes depending on the page they are on.

I'm guessing that will be done by checking the url to see what the controller is and going from there.

Any advice on this, this was confusing im sure.


Side note.. in my code the Xref is just because im new and the site is dumb and wont allow a link in a code view..
#2

[eluser]carlhussey[/eluser]
I guess my main question is..

How should I approach building the menu. Should it be a model that pulls the links from a database or is there a short code I can just add to the menu view that will check the current URI and add the class to whatever is being viewed?
#3

[eluser]benfike[/eluser]
To your public, admin, main controller:
Code:
$this->controller  = $this->router->fetch_class();
To view:
Code:
&lt;?$page = $this->controller;?&gt;

<a_XREF="#" &lt;?php if ($page == 'controllername') { ?&gt;class="nav-item-current"&lt;?php } ?&gt;>
#4

[eluser]carlhussey[/eluser]
Is that the best way to do it? Wont i have to do that for every link in there? Figured if i just put all the links into a database and created a function it would be a lot cleaner




Theme © iAndrew 2016 - Forum software by © MyBB