1

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.

ozzyna
  • 77
  • 1
  • 7
  • 1
    add quotes to the string like this- if($user == 'silver') – swapnesh Apr 14 '13 at 20:14
  • unfortunately that didn't do the trick, though it is good advice! Strangely enough this code is breaking the site (with or without quotes). When I go to /index.php/page-3 I just get a blank page. I think there's a more fundamental error in the php – ozzyna Apr 14 '13 at 20:30
  • what version of Joomla! is this for? – Craig Apr 15 '13 at 01:41
  • Joomla 3.0.3, the newest version – ozzyna Apr 15 '13 at 01:42
  • 1
    Unless you are Joomla < 1.6 user groups is going to be an array so in now way is $user == silver going to work. – Elin Apr 15 '13 at 02:23
  • I used to have it working when I was just using getUser() before and it was working, I'm just trying to expand to have more control via user groups now, if that is possible? – ozzyna Apr 15 '13 at 02:40

1 Answers1

1

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.

Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
  • Not exactly the complete answer but you gave me the inspiration to figure out the solution, so I thank you :) Your post made me realize the issue, then I did some more digging and adapted the code from http://stackoverflow.com/questions/14087419/load-css-style-only-for-specific-joomla-user-group which worked! Thank you for your help, much appreciated – ozzyna Apr 17 '13 at 04:51