Creating a menu from a categories table |
[eluser]Jondolar[/eluser]
You might not want to make the category name a unique field. It is not unreasonable for a sub menu to have the same name as some other sub menu in another branch. For example: You might have two top level menu categories of "Shirts" and "Pants". Each of them may have sub-categories of "Ladies" or "Mens". If you plan on using the category name to reference the record, then it won't work.
[eluser]skunkbad[/eluser]
[quote author="jedd" date="1259915600"]For anyone trying to follow that link - manually change the '#' to '% 23' (no space). By the way - will your data have sub-menus that contain both leaf items as well as sub-menus themselves, or will it always be a collection of one or the other only?[/quote] I don't know what these terms are, leaf vs. sub-menus. I've got a good start on what I'm working on though. Just some procedural stuff: Code: <?php
[eluser]wh1tel1te[/eluser]
Might want to have a look at Modified Preorder Tree Traversal. It is a different way of thinking about database table ordering, but once you get the hang of it, it will do exactly what you want: unlimited nesting.
[eluser]skunkbad[/eluser]
[quote author="überfuzz" date="1259928609"]My example covers infinite levels.[/quote] I didn't start playing with that because while it may be recursive, and cover infinite levels, that would mean that there is a possiblity of infinite database queries. What I'm working on now needs only one query to build the menu.
[eluser]überfuzz[/eluser]
Ehh... did you read my post..? The idea way to cache the menu. The site will be much faster. The only draw back I can see is that you'll not be able to have the clicked link marked as active. But you where making a drop-down menu weren't you? If you cache it every time someone logges out from backend, or when a cache button is fired in backend you'll end up with a fast and enough-dynamic-menu.
[eluser]überfuzz[/eluser]
Seems I spelled badly. I meant to write cache. I edited it in my previous posts. Sorry!
[eluser]skunkbad[/eluser]
Yes, caching could be beneficial. I think CI has something built in that I might be able to use. What I've got now works, and that's a good starting point for me. It's a bit of a kludge, but at least I have something. What I'd like to do now is refine my function, and make it truly recursive (if possible).
[eluser]bluepicaso[/eluser]
OK I some similar problem. I have a system where the can create categories and sub-categories. each can have tour packages and further sub-categories.. following the same rule.. Now i want to delete all the data from the category. No matter how may sub-categories they have or tours they have. I want to delete all of it... I found a code it uses a recursive function. It lists the cats and sub-cats. Code: <?php Now while translating that code to CI, I'm stuck with the declaration ofthe global varaible... Please help. The CI code is below Code: function _getCatTree() please help.. its urgent
[eluser]skunkbad[/eluser]
Take a look at the remove_children method: http://bitbucket.org/skunkbad/community-...entory.php If you follow what is going on, you could make it work for yourself. This would target the categories for you, and then you could simply delete them using a standard delete query. |
Welcome Guest, Not a member yet? Register Sign In |