php - 更新 codeigniter ion auth 中的组

标签 php codeigniter ion-auth

我是 codeigniter ion auth 的新手,并将其应用于项目中。按照 documentation 一切正常。在探索时,我注意到当我更新/编辑任何用户数据时,它不会抛出任何错误,但 users_groups 未更新。

代码:

$id = $this->input->post('id');

$data = array(
  'first_name' => $this->input->post('first_name'),
  'last_name' => $this->input->post('last_name'),
  'group' => array($this->input->post('group_id')),
  'active' => $this->input->post('active')
  );

$result = $this->ion_auth->update($id, $data);

任何帮助将不胜感激。谢谢!

最佳答案

使用ion_auth->update方法,您只能更新用户表中存储的用户属性,不能修改用户组。
(在内部它查询用户表中的列并仅更新那些属于用户有效属性的参数)
要修改用户组,您需要执行以下操作:

$user_id = 123;
$group_id = 3;// let's say 3 is the ID of the 'publisher' user group

// to remove the user (#ID:123) from the 'publisher' group call this:
$this->ion_auth->remove_from_group($group_id, $user_id);
// to remove the user (#ID:123) from all of the assigned groups call this:
$this->ion_auth->remove_from_group(false, $user_id);

// to add the user (#ID:123) to the 'publisher' group call this:
$this->ion_auth->add_to_group($group_id, $user_id);

关于php - 更新 codeigniter ion auth 中的组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37154102/

相关文章:

php - 在 Ion Auth 中检索用户的组 ID - Codeigniter

php - 选择更新

php - 使用foreach循环获取数组的值

php - codeigniter 在 url 中的方法之前传递参数?

php - Codeigniter:如何获取文件的文件名

php - 如何防止codeigniter中的自动注销?

php - 如何从 MySQL 表创建 PHP 数组

php - 我想简单地制作一个使用 zendframework2 连接到 mysql 数据库的对象

php - 在另一个表中索引数据并将其传递以匹配另一个查询时出错

codeigniter ion auth https 重定向无限循环