Welcome Guest, Not a member yet? Register   Sign In
Setting up a dynamic menu in CI
#6

[eluser]wowdezign[/eluser]
[quote author="benedmunds" date="1248627603"]That is what I want to do but how do I have the menu dynamically pulled from the database with a model, view, and controller?
[/quote]


There many ways to do it, but you could create a menu model:


Code:
class Menus extends Model{

    function Menus(){
        parent::Model();
    }

    function getMainMenu(){

        // Code to get menu data where menuType = main

    }


    function getBottomMenu(){

        // Code to get menu data where menuType = bottom

    }


    function getSubMenu(){

        // Code to get menu data where menuType = sub

    }

}


Then in your controller, you place the menu data you want in variables with something like:

Code:
$data['mainMenuArray'] = $this->Menu->getMainMenu();
$data['btmMenuArray'] = $this->Menu->getBottomMenu();

And pass them into your view like I mentioned previously.

Then in the view you can:

Code:
<ul id="mainMenuDiv">


    &lt;?php
        foreach($mainMenuArray as $item){
            echo"<li><a href='#'>$item->link_text</a></li>";
        }
    ?&gt;


</ul>


Messages In This Thread
Setting up a dynamic menu in CI - by El Forum - 07-25-2009, 10:20 PM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 05:50 AM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 05:57 AM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 06:00 AM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 06:17 AM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 06:40 AM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 09:48 AM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 11:49 AM
Setting up a dynamic menu in CI - by El Forum - 07-26-2009, 09:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB