我已经在 codeigniter 中安装了带有 Ion auth 的用户管理。现在我面临以下挑战。
登录并访问自动/索引页面时,会显示用户概览。我正在使用 3 个不同的管理员级别。每个用户都连接到一家公司。(公司 id 被添加到 users_groups 表中)
管理员公司-管理员公司-用户
超级管理员应该看到所有用户,管理员应该只看到同样在同一家公司的用户用户无权访问 auth/index(已经有效)
如何以管理员只能看到其公司用户的方式创建页面。下面是我的 auth.php 控制器的索引函数的示例。
//redirect if needed, otherwise display the user list
function index()
{
if (!$this->ion_auth->logged_in())
{
//redirect them to the login page
redirect('dashboard/', 'refresh');
}
elseif ($this->ion_auth->in_group('company-user'))
{
//redirect them to the home page because they must be an administrator to view this
redirect('dashboard/', 'refresh');
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
//list the users
$this->data['users'] = $this->ion_auth->users()->result();
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
}
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->companies = $this->ion_auth->get_company($user->id)->result();
}
}
elseif ($this->ion_auth->logged_in() && $this->ion_auth->in_group("company-admin"))
{
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
//list the users
$this->data['users'] = $this->ion_auth->users()->result();
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
}
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->companies = $this->ion_auth->get_company($user->id)->result();
}
$this->_render_page('admin/auth/index', $this->data);
}
else
{
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
//list the users
$this->data['users'] = $this->ion_auth->users()->result();
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
}
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->companies = $this->ion_auth->get_company($user->id)->result();
}
$this->_render_page('admin/auth/index', $this->data);
}
}
有谁知道我必须添加到 elseif ($this->ion_auth->in_group("company-admin")) 部分,以便仅显示与公司管理员在同一公司的用户?
///////////////////////////////////////// ////
感谢你的回答。现在我做了以下更改:
我以这种方式回答,以便有可能显示代码。我已经更改了我的控制器,但仍然可以看到其他公司的用户。我已将其更改如下:
elseif ($this->ion_auth->in_group("company-admin"))
{
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
// Check the company the user is in
$user_in_company = $this->ion_auth->get_users_companies(); // Return array groups
//list the users
$this->data['users'] = $this->ion_auth->users()->result($user_in_company);
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
}
foreach ($this->data['users'] as $k => $user)
{
$this->data['users'][$k]->companies = $this->ion_auth->get_company($user->id)->result();
}
$this->_render_page('admin/auth/index', $this->data);
}
我希望只查看公司内的用户,但我的控制器可能有问题吗?