Yii2 Yii mdmsoft获取有权访问特定路由的用户ID

Yii2 Yii mdmsoft获取有权访问特定路由的用户ID,yii2,yii2-rbac,Yii2,Yii2 Rbac,我正在使用mdmsoft/yii2管理插件。是否有任何方法可以获取对特定路由具有访问/权限的用户ID。我需要在下拉列表中只显示那些可以访问特定操作的用户 在我这么做之前,我希望这个基于Helper::checkRoute()方法的动态 第一种方法 删除->all()方法并用作子查询 $subQuery = AuthAssignment::find() ->orWhere(['item_name' => 'marketing-head']) ->orWhere([

我正在使用mdmsoft/yii2管理插件。是否有任何方法可以获取对特定路由具有访问/权限的用户ID。我需要在下拉列表中只显示那些可以访问特定操作的用户

在我这么做之前,我希望这个基于Helper::checkRoute()方法的动态


第一种方法

删除->all()方法并用作子查询

$subQuery = AuthAssignment::find()
    ->orWhere(['item_name' => 'marketing-head'])
    ->orWhere(['item_name' => 'media-head'])
    ->orWhere(['item_name' => 'production-head'])
    ->select(['user_id']);
    

$userHeadProfiles = UserProfile::find()
    ->where(['in', 'user_id', $subQuery])->all();
第二种方法

使用数组_列

$authAssignmentHeadUserIds = AuthAssignment::find()
    ->orWhere(['item_name' => 'marketing-head'])
    ->orWhere(['item_name' => 'media-head'])
    ->orWhere(['item_name' => 'production-head'])
    ->select(['user_id'])
    ->all();

$userHeadProfiles = UserProfile::find()
    ->where(['in', 'user_id', array_column($authAssignmentHeadUserIds,'user_id')])->all();

我能够获取路由的用户ID

//Getting parent roles which had access to route
$authItemParentRoles = AuthItemChild::find()
    ->where(['child' => '/voucher/accept'])
    ->orWhere(['child' => '/voucher/*'])
    ->select(['parent'])
    ->asArray()
    ->all();

//Extracting parent role onlys from given array.
$parentRoleArray = array_column($authItemParentRoles, 'parent');

//Extracting user ids whose role is in parent role array
$usersHavingAccess = AuthAssignment::find()
    ->where(['in', 'item_name', $parentRoleArray])
    ->select(['user_id'])->all();

//Lastly fetching profile or users having access to that route.
$userHeadProfiles = UserProfile::find()
    ->where(['in', 'user_id', $usersHavingAccess])->all();


感谢Shringiraj Dewangan在他的回答中使用了数组列,这是缺少的部分

我有什么办法可以让它变得动态吗?谢谢你的回答包含了一个线索,使用array_列,我可以使用它使其成为动态的哪种类型的动态?由于mdm使用父子关系进行路由,我想动态获取父角色,很抱歉,问题已过时。
//Getting parent roles which had access to route
$authItemParentRoles = AuthItemChild::find()
    ->where(['child' => '/voucher/accept'])
    ->orWhere(['child' => '/voucher/*'])
    ->select(['parent'])
    ->asArray()
    ->all();

//Extracting parent role onlys from given array.
$parentRoleArray = array_column($authItemParentRoles, 'parent');

//Extracting user ids whose role is in parent role array
$usersHavingAccess = AuthAssignment::find()
    ->where(['in', 'item_name', $parentRoleArray])
    ->select(['user_id'])->all();

//Lastly fetching profile or users having access to that route.
$userHeadProfiles = UserProfile::find()
    ->where(['in', 'user_id', $usersHavingAccess])->all();