简体   繁体   English

Joomla GetUserGroups确定徽标URL

[英]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): 对于那些精通php的人来说,这是一个简单的选择(不幸的是,我不是其中之一):

$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. 注意:我也曾尝试使用$user =&来启动此代码,但无济于事。

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. 我要用此代码执行的操作是,当用户单击网站左上角的徽标时,检查该用户所属的组,如果该用户属于silver组,则将其转到page-3 ,然后进行路由如果没有的话,他只能进入默认页面。 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. 编辑:修复了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. 我还没有测试过,但是从我的记忆中,JFactory :: getUserGroups()将返回整数数组,而不是组的实际名称。

Consider implementing some basic ACL, see the article How to add basic ACL support to your extension. 考虑实现一些基本的ACL,请参阅文章如何向扩展中添加基本的ACL支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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