在Joomla component开发中,经常会用到系统级别的权限控制,ACL就是做这个用处的。
这里举一个小例子,展示Joomla ACL的使用方法,仅当备忘。
PHP代码
- $acl = &JFactory::getACL();
- $acl->addACL( ‘com_swimtool’, ‘manage’, ‘users’, ‘super administrator’ );
- //$acl->addACL( ‘com_swimtool’, ‘manage’, ‘users’, ‘administrator’ );
- //$acl->addACL( ‘com_swimtool’, ‘manage’, ‘users’, ‘manager’ );
- $user = & JFactory::getUser();
- if (!$user->authorize( ‘com_swimtool’, ‘manage’ )) {
- $mainframe->redirect(‘index.php’, JText::_(‘ALERTNOTAUTH’));
- }
这里,先用JFactory获取ACL的对象,再添加ACL规则,最后验证,验证失败则给出失败信息,不允许访问资源。