Kohana ORM - 用户权限上的空结果



我基于2个支柱构建用户管理系统。

1. 角色

每个用户有多个角色。

2. 权利

每个角色都包含一个或多个权限。

在我的尝试中,用户和角色工作正常:

class Model_Auth_User extends ORM {
protected $_has_many = array(
'roles'       => array('model' => 'Role', 'through' => 'roles_users'),
);...}

class Model_Auth_Role extends ORM {
protected $_has_many = array(
'users' => array('model' => 'User','through' => 'roles_users'),
);...}

我正在尝试以相同的方式添加一些角色和权限:

class Model_Auth_Role extends ORM {
protected $_has_many = array(
'users' => array('model' => 'User','through' => 'roles_users'),
'rights' => array('model' => 'Right','through' => 'role_rights'),
);

class Model_Auth_Right extends ORM {
protected $_has_many = array(
'roles' => array('model' => 'Role','through' => 'role_rights'),
);

对角色的访问工作正常,如下所示:

$roles = $user->roles->find_all(); //works fine

但是,对角色权限的访问始终提供空结果:

$rights = $user->roles->rights->find_all();

因为 $user->roles i 收集

<?php
$rights = [];
foreach($user->roles->find_all() as $role){
$rights[] = $role->rights->find_all();
}

最新更新