PHP Menu Builder

PHP Menu BuilderPHP Menu Builder is a new class I just finished that allows you to easily build out a navigational menu. It outputs as an unordered list, and allows for as many levels as you want.

You can add any HTML attributes to the main list, and sub-levels and active items are given classes according to their place in the list.

View Demo & Documentation


Comments

  • WGR Studio WGR Studio July 4, 2009

    hy .. With your example i have next bugs

    Notice: Trying to get property of non-object in E:\www\menu_builder\menu.class.php on line 65

    Notice: Undefined variable: current_url in E:\www\menu_builder\menu.class.php on line 110

    Notice: Undefined variable: current_url in E:\www\menu_builder\tidy_menu.class.php on line 68

    Notice: Undefined property: tidy_menu::$attrs in E:\www\menu_builder\menu.class.php on line 149

    Notice: Undefined variable: current_url in E:\www\menu_builder\menu.class.php on line 110

    So wath happend?

    Sorry for my english

  • Corey Worrell Corey Worrell July 4, 2009

    Hey, sorry about that, and thanks for pointing it out. I updated the files on my server but forgot to update the .zip package.
    Those errors should all be fixed now in the new download.

  • WGR Studio WGR Studio July 6, 2009

    Now it works perfectly. Bravo .. : p

    I have a question unrelated to this class: Where can I find a good PHP5 class that I can manage SQL queries several drivers (I need MySQL and PostgreSQL) ... Thank you for answering me if you know.

    Best regards

  • Corey Worrell Corey Worrell July 6, 2009

    hm... I couldn't find a standalone class for that, but Kohana has a great SQL database class with several drivers.
    If you wanted to use it standalone I'm sure you could modify the classes to work.

  • WGR Studio WGR Studio July 6, 2009

    Oh of course ... Zute .. I did not think of Kohana ... Thank you...

  • InsiteFX InsiteFX August 14, 2009

    Hi Corey,

    I have searched all over the web for a MySQL database menu,

    Thats how I found your Menu Builder, I have converted it over to CodeIgniter framework.

    I was wondering if you could find the time to write up a MySQL demo or show the table structure that I would need for Menu Builder in MySQL.

    Thank you very much for a great Menu Class

    Enjoy
    InsiteFX

  • Corey Worrell Corey Worrell August 17, 2009

    @InsiteFX: I added a little section on the options page that shows a small function to generate a menu from your database. I used Kohana syntax, but it should be pretty similar to CI's.

  • ali tok ali tok February 6, 2010

    Hi Corey,
    can you add the css file, using at your example page
    thanks

  • Bassam Bassam July 12, 2010

    Hi Corey!!

    I must give you kudos for implementing such a simple menu builder class. It's very handy.

    I do however have a few questions as I have encountered some bugs/issues.

    First, if there are multiple menus using the same ID on a page, the menu drop down effects and the "hasChildren" CSS image apply to the first instance only. Other than providing the menu's with different ID (I don't want to duplicate CSS tags), is there a way to ensure all menus have the exact same "LOOK AND FEEL".

    Second, I have been trying to center the menu on the page however it's always aligned to the left. HEre is the HTML Code surrounding the menu

    [code]

    Home
    About Toastmasters
    Contact Us

    Online Contact Form
    Directions
    Meeting time and date

    Meeting Agenda

    Club Executive
    Links
    Meeting Roles

    General Evaluator
    Grammarian

    JokeMaster
    Speach Evaluator
    Speaker
    Table Topics Evaluator
    Table Topics Master
    Timer

    Toastmaster
    Quizmaster

    [/code]

    Here is my CSS

    [code]
    #nav {
    background: #e5e5e5;
    float: left;
    margin: 0; padding: 0;
    border: 1px solid white;
    border-bottom: none;
    border-style: none;
    }

    #nav ul {
    list-style-position: outside;
    position: absolute;
    }

    #nav li a, #nav li {
    float: left;
    }

    #nav li {
    list-style: none;
    position: relative;
    }

    #nav li a {
    padding: 1em 2em;
    text-decoration: none;
    color: white;
    background: #72634D;
    background: -moz-linear-gradient(top, black, #292929 1px, #72634D 25px);
    background: -webkit-gradient(linear, left top, left 25, from(black), color-stop(4%, #292929), to(#72634D));
    border-right: 1px solid #72634D;
    border-left: 1px solid #292929;
    border-bottom: 1px solid #232323;
    border-top: 1px solid #545454;
    }

    #nav li a:hover {
    /*
    background: #1153c0;
    background: -moz-linear-gradient(top, #0b2b61, #1153c0);
    background: -webkit-gradient(linear, left top, left bottom, from(#0b2b61), to(#1153c0));
    */
    background: #8F001A;
    background: -moz-linear-gradient(center top , #750000, #8F001A);
    background: -webkit-gradient(linear, left top, left bottom, from(#750000), to(#8F001A));
    }

    /* Submenu */

    .hasChildren {
    position: absolute;
    width: 5px; height: 5px;
    /*background: black */
    background: url(/images/hasChildren.jpg);
    right : 2px;
    bottom: 2px;
    }

    #nav li ul {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    padding: 0; margin: 0;
    }

    #nav li:hover > ul {
    display: block;
    }

    #nav li ul li, #nav li ul li a {
    float: none;
    }

    #nav li ul li {
    _display: inline; /* for IE6 */
    }

    #nav li ul li a {
    width: 150px;
    display: block;
    }

    /* SUBSUB Menu */

    #nav li ul li ul {
    display: none;
    }

    #nav li ul li:hover ul {
    left: 100%;
    top: 0;
    }
    [/code]


Add Comment

  • (optional)