简体   繁体   中英

Joomla GetUserGroups to determine logo URL

Here's an easy one for those who are well-versed in php (unfortunately, I am not one of them):

$user = JFactory::getUserGroups();
if($user == 'silver')
{
    //link to page for registered users 
    $link =  JRoute::_('/index.php/page-3');
}
else
{
    //link to page for default users 
    $link =  JRoute::_('/');   
}

Note: I have also tried to start this code with $user =& to no avail.

What I'm trying to do with this code is to check the group the user belongs to when he clicks on the logo at the top left of the website, and route him to page-3 if he belongs to the group silver , and route him to just the default page if not. Basically, I have different pages set up as index pages for different groups, and I'm trying to route appropriately.

The code above is something I hacked together based on a sample code I saw somewhere else but clearly something is not working because using this script is breaking the site :)

Edit: Fixed a syntax error as suggested by swapnesh. The original question is still valid.

I haven't tested it, but from my memories JFactory::getUserGroups() will return and array of integers and not the actual name of the group.

Consider implementing some basic ACL, see the article How to add basic ACL support to your extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM