Jump to content

User Permissions and Dynamic Menu (parent, child, grandchild)


Recommended Posts



I am using the following Menu Manager http://codecanyon.ne...r-system/637633 to create a dynamic menu for an application.

The menu contains a parent, child and grandchild (or parents, children, grandchildren)


Here is an example:


User Profile
| --> Faculty Dashboard
       | --> Dashboard Settings
       | --> Send Faculty Email
| --> Exam Schedule
       | --> Add/Edit Exam Time
       | --> View Exam Schedule


When the user logs in to the application, I would like a specific menu to be displayed depending on the user's role/group (Admin gets all menu items and has full access).


I have researched various ways to get the user's permissions (sessions, arrays, query the DB each time the user clicks a page, etc.) but I want to avoid unnecessary overhead but allow users to see their menus (and not be able to access other pages).


For example, let's say I have a user who has the role of "Leader" and I want to give the user/role/group access to the following page only: WLM --> Faculty Dashboard --> Send Faculty Email (as shown above).


I was thinking of several DB tables (User, Group/Role, Resources/Pages, Permissions), however, how would I go about getting only the specific menu items for the user/group?


The challenge is the Menu Manager stores the menu items (parent, child, grandchild) in one database table (please see the attached screenshot).


Is there a way to easily go through the table for this? OR should I not use the menu manager and try a different approach?


Any help/feedback would be greatly appreciated.


Thank you!


Link to comment
Share on other sites

Have a table that associates the menu id's with the users (or groups) then just join to the menu table using that ID to pull the menu data.  Eg:

  UserID  |  Username    |  GroupID
    1     |  Blah        |     1
    2     |  Flarg       |     2

  GroupID    |  Groupname
    1        |    Admins
    2        |    Users

   GroupId   |  MenuID 
      1      |    1
      1      |    4
      2      |    2
      2      |    3
      1      |    6

  MenuID    |    Name
    1       |    Manage Users
    2       |    Profile
    3       |    Invite
    4       |    Mass Email
    6       |    Bans


FROM users u
INNER JOIN groups g ON u.GroupId=g.GroupId
INNER JOIN group_menu_items gm ON gm.GroupId=g.GroupId 
INNER JOIN menu m ON gm.MenuId=m.MenuId


Link to comment
Share on other sites

Hi Gurus,

Thanks for your reply.

Based on your suggestion, if the user is part of a group that has permission to view a grandchild menu item, how can I display the parent in the main menu, then the child in the sub-menu and finally the grandchild (as a sub-menu of the child)?

Thanks again.

Link to comment
Share on other sites

Since the menu uses the nested set model it's relatively easy to query for the parents of a menu item.


Something like this would probably do:

m.MenuId, m.Name, p.MenuId, p.Name
FROM users u
INNER JOIN groups g ON u.GroupId=g.GroupId
INNER JOIN group_menu_items gm ON gm.GroupId=g.GroupId 
INNER JOIN menu m ON gm.MenuId=m.MenuId
LEFT JOIN menu p ON m.lft BETWEEN p.lft AND p.rgt


You'd probably need to do a little processing of the results within PHP to get them in whatever format the menu system's render function needs.


Link to comment
Share on other sites

  • 2 months later...

Hi again,

I'm not sure if it is acceptable to return to this previous post or start a new one.  

I have since changed my approach for the dynamic menu than the one noted above.

The current menu system works better for me in regards to creating menu items. 

However, assigning page permissions to a role is challenging.  I have a page that displays the hierarchy tree and on clicking a submenu item I would like to have the parent automatically checked. 

Since the submenus can go deep several levels I think I need a recursive function to accomplish this. I would also like to do this using jQuery/ajax.

And yet another challenge is when I edit the permissions for a role - if permissions have been previously set, I would like to have those check boxes populated.

Permissions for each role will be saved in a dbTable.  

I have attached some screenshots of the menu and the dbTable of the menu items.

Any advice on how to go about this?  Any sample code? 

Thanks! Much appreciated.





Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.