CakePHP: CakeMenu plugin

I am using it for a while, but today I’ve decided to publish in the github.com.

What this plugin does?

The plugin is complete solution to add menu in your applications. It uses the nifty Superfish – jQuery menu plugin. You can find more info for it at http://users.tpg.com.au/j_birch/plugins/superfish/

Cakemenu can work with multilevel menus and reduces the database calls by caching the menu nodes. The plugin working with Authake plugin if you need to apply filter to menu nodes (user need to see only allowed locations)

Cakemenu working with CakePHP 1.2 but it’s tested with Cakephp 1.3 (RC3) and it would not have any problems with the future releases so far.

Requirements

  • CakePHP 1.3 (of course)
  • jQuery in the head tag
  • Authake (optional) if you require your menu nodes to be filtered when user with limited privileges is logged in. Actually it’s possible to use other authorization class, but you have to extend it.

I believe that’s it. Check the large README file in the project’s directory.

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

30 thoughts on “CakePHP: CakeMenu plugin

  1. Nik,

    Thanks very much for publishing this. I was *just* about to work on integrating my own home-brew menu system with Authake isAllowed.

    I had the menu system working on a stock CakePHP test system in about 10 minutes. I then added it to my Authake/SSO test system. There I see some warnings I expect because I have existing “menu” MVC. I think I will rename that to “menu_pages” but maybe keep it to redundantly display menu elements as simple list on top-level parent menus elements. If I am good, I hope I can use same menu table and your isAllowed logic.

    I think I am still stuck at being a procedural programmer at heart, so I especially enjoyed looking at your economical controller code for this menu system. With examples like yours someday I will be more OO 🙂

  2. loops quite promising

    does it work with other auth components as well?
    or how difficult will it be to switch the “auth” mechanism behind it?

  3. Hi Mark,

    for now it’s working with Authake because I am using that Auth plugin, but it can work with any other if it has 2 methods: Auth->isAllowed($path) and Auth->getUserId(). See the readme file in the github 🙂

  4. Hi, Nik,

    Authake working and cakemenu working, but auth not filtering menu (yet!). As usual, I am probably missing something.

    I assumed that I could enable cakemenu+authake in BeforeFilter nodes() like so:

    $menuauth = true;
    $this->set(‘menu’, $this->Cakemenu->nodes(array(),$menuauth, ‘menu’));

    I have tried variations including editing the values for auth in the controller (which I wouldn’t think would be the right way necessarily). Any simple guidance for the perpetually lost? 🙂

  5. Jim,
    $menuauth is not boolean. It’s an instance of the Authake’s component. The first line – you don’t need it.

    The second line should look like:
    $this->set(‘menu’, $this->Cakemenu->nodes(null, $this->Authake, false));

    and also you need to clear the cache

  6. As they say, “Bingo!”. Many thanks for your patience. I had also tried just ‘Authake’ but without the object reference.

    I am really going to start having fun now.

    Jim

  7. Hello, Nik, and Happy New Year.

    I am finally getting back to my adminsitrative DB project with Authake and Cakemenu. From time to time I create an infinite loop by breaking an Authake rule, but that happens less and less 🙂

    Along with the ability to make Cakemenu hierarchical with parent and child relationships, I have tended to make the links hierachical as well (like a top-level menu of “Financial” with link /financial and a child called “Budgets” with link /financial/budgets).

    Since the controller layout is pretty flat, I have entered all of these into routes.php so that /financial/budgets maps to /budgets (budgets controller).

    I do wonder a couple of things: am I making my life more complex from a rules standpoint? Do I need to create separate rules for the route /financial/budgets and /budgets as well, or will my “deny all” save me the bother? I think the latter case is true, but I get anxious 🙂

    Secondarily, I started thinking about extending Cakemenu table structure to include all elements found in routes.php, then have an admin function that write out routes.php (or include file) from the Cakemenu database when changes are made. I am just thinking that the more items I add to the menu, the more work it will be to maintain corresponding routes.

    My thinking is that it would nice to have routes be DB-derived but not hit the database for every menu operation.

    Thoughts?

    Jim

  8. Hello… i have started to use this one.

    But facing a little bit problem to filter the menus with cakephp auth component. Can you give me some idea?

    Thanks in advance.

  9. Thanks for your prompt reply.

    Actually, Cakephp acl or auth component doesnt have these methods.
    Auth->isAllowed($path) and Auth->getUserId()

    So how could i filter the menus as
    every logged user will see only menus which are accessible to him.

  10. What you need to do is to create a component which extends auth/acl component and has these two methods isAllowed($path) and getUserId().

    The first function should accept path like ‘/users/index’ and then to check this path against the logged user and depending from state allowed or not to return true or false.

    The second function is even simpler – it shold be something like:
    function getUserId(){
    retur $this->user(‘id’);
    }

    Sorry that my explanation is theoretical, but I don’t have time to check it with real example.

    Regards

  11. This is an awesome plugin, thank you! I had spent many hours looking for a nice drop down menu and found hundreds of examples, all with significant problems. I had finally decided to go with superfish because it seemed the best and just stumbled on this plugin. This made my day!

  12. Has anyone created a component to extend the built in cake auth component to work with this plugin?

  13. Hi, I’ve been experiencing a problem and am not sure if it is with CakeMenu or something else in my CakePHP project. In normal operation, CakeMenu works fine. However if my current url is to CakeMenu itself, the links in the menu bar are incorrect. For example, my url while editing the menu is http://localhost/sim/cakemenu. The configuration I use for one of the menu options is array(‘controller’=>’part_numbers’,’action’=>’index’), but when I choose that the link generated is ‘http://localhost/sim/cakemenu/part_numbers’ which doesn’t exist due to the ‘cakemenu’ after ‘sim’. Is there a trick to not include the ‘cakemenu’? Currently I have to click a link to ‘/’ and then the menu links are correct.

  14. Thanks that works! Although it exposes some thinks I don’t know about routing, time to hit the manual again.

  15. Hey, I didn’t noticed that CakePHP 2.0 stable is out :)) Of course I have plans for that, but I haven’t project which I can use 2.0 and requirement for the menu like this.

    I will try to make it as soon as I can.

  16. Nik,

    It is 2.0.1 now. I did not notice either. I see announcement of a “2.0-compatible” Authake from another dev, but your addition of CakeMenu is compelling, so I will stay with 1.3 unless you find time to adapt to 2.0.

    I do see some nice things in 2.0 like better upgrade scripts/shells. Why should we upgrade? Because the upgrade is easier! 🙂

    Thanks!

    Jim

  17. Hi Jim,

    I am not supporter of the idea that every app should upgrade to the last version of the framework just because it’s better. If it’s working – stay with it, if there are bugs or you missing some features – then upgrade. I am supporting an app with Cake1.2 and it still do what it has to do and I am not going to upgrade it, because will cost me huge amount of time and nerves.

    The upgrade of the menu plugin should be just because more and more developers will start using the 2.0. I don’t think it will be a big task to upgrade, but so far I just don’t have time.

  18. I have a working version of Cakemenu for CakePHP 2.0. Is there a way for me to upload it to github, as a fork or something like that? I don’t guarantee that everything works, but it seems to be OK.

  19. I can’t figure out how to get github to work behind my proxy (why is that always so hard with open source projects?) I did fork Cakemenu on github, but I’m really not sure what to do now since I can’t clone it to my PC. If anyone wants a zip of what I have so far, just let me know. Maybe someone else can clone the fork and update it?

  20. I got it on github. Is there something I need to do to push it back to the original project? My knowledge of git (and version control) is close to 0. Hope the update helps someone. FYI, I did not test at all Authake.

  21. Matt,

    Getting back to my project and thinking about upgrade to Cake 2.x

    I see your fork on GitHub. Did you ever come to a final conclusion/approach to the question you posed on Stackoverflow re: “CakePHP Cakemenu plugin fails after global error due to incorrect string encoding”?

    Thanks,

    Jim

  22. Pingback: CakePHP: CakeMenu plugin | Blog for web development | blog

Leave a Reply

Your email address will not be published. Required fields are marked *