Yii Framework Forum: Tbauthmenu: Access Checks For Your Menus - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Tbauthmenu: Access Checks For Your Menus Hide/show menu items using RBAC Rate Topic: -----

#1 User is offline   danschmidt5189 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 19-February 13

Posted 30 April 2013 - 12:29 PM

Hi all,

I whipped up a quick extension to the TbMenu/CMenu class that allows showing/hiding menu items using RBAC. There are a few extensions that do something similar, but they didn't offer the control I needed and/or overrode my settings with odd defaults.

Parameters / Features:
  • authCheckAll - Whether to check every menu item, even if its authItem is not specified
  • authCheckNestedItems - Whether to check sub-items. (Ie $item['items])
  • authItem - Name of the auth item to check
  • authParams - Array of parameters to pass to checkAccess
  • authUser - ID of the user to check access for. Defaults to current user.
  • authResult - The expected return value of checkAccess. If something else is returned, the item and its children won't be displayed


Parameters are checked at both the menu and item levels, with item-level parameters taking precedence.

Hope it helps!
- Dan

Attached File  TbAuthMenu.php (4.94K)
Number of downloads: 39
0

#2 User is offline   Fabrizio Caldarelli 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 336
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 30 April 2013 - 03:10 PM

In my opinion, it is more simple to set "visible" attribute of menu item, using CMenu.
0

#3 User is offline   danschmidt5189 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 19-February 13

Posted 30 April 2013 - 07:51 PM

View PostFabrizio Caldarelli, on 30 April 2013 - 03:10 PM, said:

In my opinion, it is more simple to set "visible" attribute of menu item, using CMenu.


I did this originally and ended up with cluttered code. YMMV. This also frees up the visible attribute for other logic. (Which could be done your way as well, but with a cost to readability.)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users