mbmenu

MbMenu dropdown menu
58 followers

MbMenu is an extension to CMenu wich provides you a nice dropdown menu.

Resources

Documentation

Requirements

  • Yii 1.0 or above
  • Tested on IE6/IE7/IE8/Firefox/Chrome

Installation

  • Extract the 'mbmenu' folder under protected/extensions

Usage

The usage of this extension is allmost the same like CMenu.

The following example shows how to use MbMenu:

<?php $this->widget('application.extensions.mbmenu.MbMenu',array(
            'items'=>array(
                array('label'=>'Home', 'url'=>array('/site/index')),
                array('label'=>'Contact', 'url'=>array('/site/contact'),
                  'items'=>array(
                    array('label'=>'sub 1 contact'),
                    array('label'=>'sub 2 contact'),
                  ),
                ),
                array('label'=>'Test',
                  'items'=>array(
                    array('label'=>'Sub 1', 'url'=>array('/site/page','view'=>'sub1')),
                    array('label'=>'Sub 2',
                      'items'=>array(
                        array('label'=>'Sub sub 1', 'url'=>array('/site/page','view'=>'subsub1')),
                        array('label'=>'Sub sub 2', 'url'=>array('/site/page','view'=>'subsub2')),
                      ),
                    ),
                  ),
                ),
            ),
    )); ?>

Replace

<div id="mainmenu">

with

<div id="mainMbMenu">

to avoid conflicts with the standard CSS for the menu.

Change Log

January 23, 2012

  • v1.3 fix mentioned by Zyphers in function normalizeItems

February 23, 2010

  • v1.2 fix for IE7

February 22, 2010

  • v1.1 minor update in creation of class styles

February 18, 2010

  • Initial release.

Total 20 comments

#11871 report it
ItsYii at 2013/02/10 04:44am
Active/Current selected Image

Hi I'm trying to have a different image depending on the page I'm on (like an active or current link). Here is my code.

array('label'=>'<img src="'.Yii::app()->request->baseUrl.'/images/products.gif" />', 'url'=>array('/category/index'),
                  'items'=>$items, 'active'=>'<img src="'.Yii::app()->request->baseUrl.'/images/products-on.gif" />'
                ),

'active'=> This doesn't have any effect.

Also is there a hover feature for images too

Thanks

#11044 report it
kiran sharma at 2012/12/12 03:52am
@mr.shadoww

try after removing assets files under projectFolder/assets/*

#11043 report it
mr.shadoww at 2012/12/12 03:46am
still

@kiran sharma at protected\extensions\mbmenu\source folder..i change the nav1_active1.gif file, it suppose to be change the color of the menu, but it don't, and you know what? even all file at protected\extensions\mbmenu\source folder i deleted and let the ..\source folder empty it's still give me the same menu layout...:( have you try to vanished file in the ..\source folder??

#11028 report it
kiran sharma at 2012/12/11 04:00am
@mr.shadoww

i had use this extension much time before. and as i know menu background is generated by image(s), so to change background color you had to replace that image(s). you can found that images and their path by inspect element.

#11027 report it
mr.shadoww at 2012/12/11 03:53am
how to change menu background color

seriously i can't change or modify the menu style, event all asset in protected\extensions\mbmenu\source i deleted it still not effect.

#10185 report it
brunocalado at 2012/10/09 10:51am
Customize MBMenu CSS

I'm having trouble to change the style. How can I do it?

#9366 report it
ItsYii at 2012/08/07 05:35am
Generate Model drop down

How can I make the drop down list automatically gather all my models, is it possible with this extension? So for example if I click on one of my Menu items "Products" I want all the products model to show on the drop dow.

Thanks

#8208 report it
Solleon at 2012/05/17 03:00pm
Awesome!

Very nice extension! Awesome!

#6938 report it
bilijen at 2012/02/14 05:16pm
Works out of the box

Great extension, thank you!

#6598 report it
zyphers at 2012/01/20 04:18am
hideEmptyItems property doesn't work

As CMenu's hideEmptyItems property is a bug according to issue 3029. And it's already fix in Yii's 1.1.9 as MbMenu bases on CMenu and has override a function normalizeItems so it should be fixed too.

#6052 report it
Alexandre Sena Coelho at 2011/12/08 05:40am
Very nice extension

It's useful for me. Great job!

#5998 report it
javed alam at 2011/12/04 06:37am
Ajax links

How can we use Ajax links.

#5950 report it
Fixticks at 2011/11/28 01:14pm
Important instructions, thanks nafa

Why isnt this part of the installation instructions. change div id = "mainmenu"> to.. div id = "mainMbMenu">

in protected/views/layouts/main.php

#5655 report it
StarSight at 2011/10/28 10:04pm
Can not change Styles (cont)

I have now cleared the Assets folder in the root directory (was not previously familiar with it), and I still can not edit the styles. Changes made to the mbmenu.css file in the /protected/extensions/mbmenu/source folder do not edit the menu. I assume the menu would use the mbmenu.css for formating, but I can delete the file with no effect to the menu styling. The current styling of the menu is the same as the example at http://yii.heyhoo.com/mbmenu/. What else could I check? Thanks for your help.

#5645 report it
heyhoo at 2011/10/28 05:33am
CSS Styles

@starsight: did you clear the assets folder?

#5638 report it
StarSight at 2011/10/27 10:00pm
Can not change Styles

Have tried to edit the mbmenu.css file in the extensions/mbmenu/source folder but there were no changes. What could be wrong?

#4666 report it
TeKi at 2011/08/01 10:54pm
siskalandre

Hi, I modified your function. The only thing I did was add the directory containing the icons in the extension. In my opinion this better ordered.

if (isset($item['image'])) {
 $item['image'] = $ this->baseUrl. '/icons/'. $item['image'] //add this line
 $imghtml = chtml::image($item['image'], $item['label']);

and within the source directory, I created a directory called icons.

Finally in the menu instead of calling "image" with the path, I indicate only the name of the image.

certainly, this isn't the best choice but works for me.

#4451 report it
siskalandre at 2011/07/10 06:55am
just shared: extend with image

I had extend your mbmenu extensions with icon and text

Mbmenu.php

protected function renderMenuRecursive($items)
      {
          foreach($items as $item)
          {
            echo CHtml::openTag('li', isset($item['itemOptions']) ? $item['itemOptions'] : array());
            if(isset($item['url']))
            {
              if(isset($item['image'])) {
                $imghtml=CHtml::image($item['image'], $item['label']);
                echo CHtml::link('<span>'.$imghtml.' '.$item['label'].'</span>',$item['url'],isset($item['linkOptions']) ? $item['linkOptions'] : array());
              } else
                echo CHtml::link('<span>'.$item['label'].'</span>',$item['url'],isset($item['linkOptions']) ? $item['linkOptions'] : array());
            }
            else
                echo CHtml::link('<span>'.$item['label'].'</span>',"javascript:void(0);",isset($item['linkOptions']) ? $item['linkOptions'] : array());
            if(isset($item['items']) && count($item['items']))
            {
                echo "\n".CHtml::openTag('ul',$this->submenuHtmlOptions)."\n";
                $this->renderMenuRecursive($item['items']);
                echo CHtml::closeTag('ul')."\n";
            }
            echo CHtml::closeTag('li')."\n";
          }
      }

and how to use

array('label'=>'Home', 'url'=>array('/site/index'),
                      'image'=>Yii::app()->request->baseUrl.'/images/home.png'),
#4135 report it
Artur Oliveira at 2011/06/08 09:55pm
IE <8 problem solved if theming

To theme this fine menu extension all you need to do is define 'cssFile'=>'/some/url/to/file.css' and copy the images to the same directory.

This is good cause this way you can customize the images too without changing the original extension code

However with the existing code there is a small problem:

  • The file mbmenu_iestyles.css is not loaded

To solve this you have to change the extension file protected/extensions/mbmenu/MbMenu.php from:

public function registerCssFile($url=null)
      {
        // add the css
        if ($this->baseUrl === '')
            throw new CException(Yii::t('MbMenu', 'baseUrl must be set. This is done automatically by calling publishAssets()'));
 
          $cs=Yii::app()->getClientScript();
          if($url===null) { 
              $url=$this->baseUrl.'/mbmenu.css';
          $cs->registerCssFile($url,'screen');
          $browser = Browser::detect();
          if ($browser['name'] == 'msie' && $browser['version'] < 8)
            $cs->registerCssFile($this->baseUrl.'/mbmenu_iestyles.css','screen');
        } else {
            $cs->registerCssFile($url,'screen');
        }
      }

To:

public function registerCssFile($url=null)
      {
        // add the css
        if ($this->baseUrl === '')
            throw new CException(Yii::t('MbMenu', 'baseUrl must be set. This is done automatically by calling publishAssets()'));
          $cs=Yii::app()->getClientScript();
          if($url===null) 
              $url=$this->baseUrl.'/mbmenu.css';
          $cs->registerCssFile($url,'screen');
          $browser = Browser::detect();
          if ($browser['name'] == 'msie' && $browser['version'] < 8)
            $cs->registerCssFile($this->baseUrl.'/mbmenu_iestyles.css','screen');
      }

Everything works ok.

  • The assets folder is created

  • The file mbmenu.css and the images are loaded from the alternate directory /some/url/to/

  • The file mbmenu_iestyles.css is loaded from the original assets directory

This is only a problem if you use IE < 8 whichif you want a really cross browser webapplication is important

Hope this helps.

Good coding!!!

#3734 report it
nafa at 2011/05/03 02:38am
yipee

This extension works well with me.. The most important things, make sure that you modify the

<

div id = "mainmenu"> to..

<

div id = "mainMbMenu">

Leave a comment

Please to leave your comment.

Create extension