首页 > 解决方案 > Ion Auth in_group() - 多个组(按 id)

问题描述

我的应用程序中有一些关于 Ion Auth in_group 函数的奇怪行为。

我经过身份验证的用户是第 2 组的一部分。当我执行代码$this->ion_auth->in_group(2)?'success':'fail';时,结果是“成功”,这是预期的结果。

$this->ion_auth->in_group(2,4,5)?'success':'fail';传递一个类似, $this->ion_auth->in_group(array(2,4,5))?'success':'fail';or的数组$this->ion_auth->in_group($group_ids)?'success':'fail';总是会导致“失败”,这是意料之外的。

我可以确认$group_ids结构正确:

Array
(
    [0] => 2
    [1] => 4
    [2] => 5
)

正如Ion Auth 文档所解释的那样:TRUE if the user is in any of the given groups, FALSE otherwise. 我可能做错了什么?

使用的 Ion Auth 版本:2.5.2

作为当前的工作(我不想要硬编码的组),我正在使用$this->ion_auth->in_group('order')?'success':'fail';我的数据库看起来像这样:

INSERT INTO user_groups(id, name, description, can_order)
VALUES(1,'admin','admin',0),
    (2,'order','internal',1),(3,'controller','controller',0),
    (4,'order','external 1',1),(5,'order','external 2',1)

标签: phpion-auth

解决方案


尝试使用来自Github中“2”分支的最新 Ion Auth 代码。几个月前对组内功能进行了错误修复,它可能是相关的。


推荐阅读