Welcome Guest, Not a member yet? Register   Sign In
Menu Library 1.3 [05 Gen 09]
#41

[eluser]Bob Sawyer[/eluser]
OK, having a problem getting the parent menu item of a submenu to reflect the "current" class. Here's the menu:
Code:
$menu = array(    anchor('/home','Home'),
    anchor('/about','About'),
    anchor('/printing','Printing') => array(
        anchor('/printing/offset','Offset'),
        anchor('/printing/digital','Digital'),
        anchor('/printing/large_format','Large Format')
        ),
    anchor('/design','Design'),
    anchor('/estimates','Estimates') => array(
        anchor('/estimates/request','Get an Estimate')
    ),
    anchor('/uploads','Uploads'),
    anchor('/contact','Contact Us')
    );
echo $this->menu->create($menu, 'ul', array('id' => 'sf-menu'));;

I'm using Superfish menus with this as well for nice hovers/dropdowns. Anyway... if I click "Printing," it does not get assigned the "current" class, nor does it if I click "Offset," "Digital," etc.

Now... I changed the following block in the Menu.php library from:
Code:
if ( ! is_array($val) ) {
    $status = $this->_check_current($val);
}

to this:

Code:
if ( ! is_array($val) ) {
    $status = $this->_check_current($val);
} else {
    $status = $this->_check_current($key);
}

This assigns the current class to the parent item, but now the dropdowns stay in the "open" position, AND the item doesn't take on the "current" styling.

Thoughts?
#42

[eluser]rubab.11[/eluser]
I am new to use codegniter and want to create menu and I find Menu Library ver 1.3 in codeigniter forum but when I was trying to create menu as mentioned in Menu Library ver 1.3 but it shows
menu->create('primary_menu')?> in browser
#43

[eluser]davidbehler[/eluser]
Can you show us what your files look like?
It's hard to tell what's wrong without seeing atleast some of your code Wink
#44

[eluser]rubab.11[/eluser]
[quote author="waldmeister" date="1233942452"]Can you show us what your files look like?
It's hard to tell what's wrong without seeing atleast some of your code Wink[/quote]


thanks i solved actually i was typing following statement

<? echo $this->menu->create('primary_menu','ul', array('id' => 'menu', 'class' =>'fallout'))?>

when i wrote

<?php echo $this->menu->create('primary_menu','ul', array('id' => 'menu', 'class' =>'fallout'))?>

when is use

<?=?> and <? echo ?>

codeigniter doesn't show me correct output that's why menu was not shown......
#45

[eluser]Bob Sawyer[/eluser]
OK, regarding my last post, I figured out the issue with the menu staying in the open position (it's been a while so I don't remember what - I think I just returned the code to its original state), but I was still having a problem getting submenus to take on the "current" class. The top-level menu would not take the class, but all 3 submenu items were being assigned the class, so all my subs were highlighted.

Well, tonight I figured out a fix for that. Here's the code. Change function _check_current($match) from:

Code:
function _check_current($match)
    {
        // Var
        $current_tag = $this->ci->config->item('current_tag');
        $segment = get_class($this->ci);// Current Controller Name
        
        // Check the existence of a case-insensitive string
        // in the link, matched with current url
        return (strripos($match, "/" . $segment) == TRUE) ? ' class="' . $current_tag .'"' : NULL;
    }

To this:

Code:
function _check_current($match)
    {
        // Var
        $current_tag = $this->ci->config->item('current_tag');
        if ($this->ci->uri->segment(2))
            $segment = $this->ci->uri->segment(2);
        else
            $segment = $this->ci->uri->segment(1);
        
        // Check the existence of a case-insensitive string
        // in the link, matched with current url
        
        return (strripos($match, "/" . $segment) == TRUE) ? ' class="' . $current_tag .'"' : NULL;
    }

Basically, this says, don't match the loaded class -- match the URI segment. If there's no submenu (i.e., /about) it assigns the "current" class to the top-level item; if segment(2) -- a submenu, i.e., /printing/digital, exists, assign the "current" class to that instead.

Cheers,
Bob

PS - I'm fully aware that if I simply created a new controller and view for those submenu items, that none of this would have been necessary... :-)
#46

[eluser]Référencement Google[/eluser]
Trying this menu in a real life app, it's working with the change of Sofbas above, Dewos you should redistribute the ZIP including this change.

Also there is a risk of duplicate content with your menu, with the Home page link for example because your menu require to have the home link like anchor('welcome', 'Home'), that will make 2 links pointing to the same page. Of course you can use a redirect, but I feel like a redirect directly at top of a controller is a real dirty way, something should be done in the menu code.

Thoughts ?
#47

[eluser]Flak[/eluser]
@dewos, have you managed to get it from db, I'm new to CI, and I can't decide in which file to write the code.

I don't know but my idea was to make a table navigation, one of the field will be `type` where I can make it primary, secondary, top, left, admin etc. and I will use
Code:
<?=$this->menu->create('navigation','primary')?>
.

Drupal has same logic. What do you think of it. Also if is already a way to get items from db with current, let me know.

Thanks. Flak.
#48

[eluser]matyhaty[/eluser]
hi there

love this lib and use on a few sites.....

what i have struggled with a few points, wonder if anyone can help....

Last in list:
Often when you get to the last -li- (for example) you want a class such as 'last' to be applied... is this possible?

Also the currently selected just doesnt seem to work for me, it 'appears' that its is not matching... any clues

thanks
#49

[eluser]mashary[/eluser]
thanks this is very usefull menu Smile
#50

[eluser]Unknown[/eluser]
I also needed to create a menu system with a first and last class added to the elements. So quickly rewrote the library to allow for this. The current selection of the menu now also works.

Menu library attached

The Menu config works like this:
(can accept arrays for submenu items or just a string for one level items)
Code:
$config['navigation'] = array(
        "Home" => "",
        "Item 1" => array("page1", array()),
        "Item 2" => array("subpages", array(
            "Item 2.1" => "subpages/page1",
            "Item 2.2" => array("subpages/page2", array()),
            "Item 2.3" => "subpages/page3",
        )),
        "Item 3" => "another_page",
        "Contact Us" => array("contact_us", array()),
);


And call the menu in the same way:
Code:
<?=$this->menu->create('navigation','primary')?>

I hope this helps




Theme © iAndrew 2016 - Forum software by © MyBB