我正在尝试将用户添加到组中。我可以运行这个 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/