joomla - 在 Joomla 中将用户添加到组不起作用

标签 joomla joomla3.4

我正在尝试将用户添加到组中。我可以运行这个 PHP 代码,没有任何错误,但用户组仍然没有改变。

<?php

define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );

$userId = 358;
$groupId = 11;

echo JUserHelper::addUserToGroup($userId, $groupId);

?>

最佳答案

我在付款回调方面遇到了同样的问题。我发现用户组正确保存在数据库中,但没有在 Juser 对象中刷新(因为您在不同的 session 中将用户添加到组)。当用户在页面上进行交互时,组将被恢复。

我发现的另一个想法是,如果用户登录,在管理员面板中更改组的工作方式相同。

为了处理它,我制作了系统插件,并在 onAfterInitialise 函数中执行:

//get user
$me = JFactory::getUser();
//check if user is logged in
if($me->id){
    //get groups
    $groups = JUserHelper::getUserGroups($me->id);
    //check if current user object has right groups
    if($me->groups != $groups){
        //if not update groups and clear session access levels
        $me->groups = $groups;
        $me->set('_authLevels', null);
    }
}

希望能有所帮助。

关于joomla - 在 Joomla 中将用户添加到组不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29580646/

相关文章:

php - 1146 表不存在

pagination - 如何为组件前端添加分页 (Joomla 3.4)

php - 设置 JText 的语言::_()

php - 通知 : Undefined property: stdClass error on front end

javascript - 在 Joomla 上使用自定义 HTML 轮播消失

joomla - 如何在joomla中设置文章宽度?

joomla - WordPress 是否像 Joomla 那样提供插件覆盖功能?

javascript - Joomla - "Menu Item Type"弹出窗口为空

php - 从传入的 url 在 php 或 htaccess 中重定向

php - Joomla:onContentAfterSave 未触发