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

[eluser]qwertyqwerty[/eluser]
I wouldn't have thought to extend the Controller class and that is an interesting way of doing it and it would certainly work.

For the example of your main menu, I've created a helper function called 'main_menu()' and all it (basically) does is the following:

- Loads the Page model
- Calls the 'getMainMenu()' method from the page model which returns an associative array.
- Passes the returned associative array to Code Igniter's ul() helper function to generate the unordered list
- Returns the HTML (Important, it does not echo it)

Then in your template, you just put the following to spit out your main menu

Code:
<?php echo main_menu(); ?>


For all I know, this could be really bad practice in terms of correctly utilizing the MVC pattern, but it's the easiest and cleanest way I've found so far.

Note:
You'll need to specify how deep you want the traversal to go.
You'll need to indicate for each of your pages whether you want them to display or not as sometimes, you'll have pages at the root level (e.g. privacy) that you won't want showing up in the main menu.


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