gpt4 book ai didi

mysql - ion_auth 与另一个表连接的事件记录/方法

转载 作者:行者123 更新时间:2023-11-29 11:37:41 25 4
gpt4 key购买 nike

我现在正在使用ion_auth,在 ion_auth 中,我们可以像这样选择所有记录:

Controller

 public function index($group_id = NULL) {
$before_head = $this->load->view('admin/users/v_before_head', '', TRUE);
$before_body = $this->load->view('admin/users/v_before_body', '', TRUE);

$this->data['page_title'] = 'Users';
$this->data['before_head'] = $before_head;
$this->data['before_body'] = $before_body;
$this->data['users'] = $this->ion_auth->users($group_id)->result();
$this->render('admin/users/v_list_users');
}

我的情况是,我在名为 id_departement 的默认表 ion_auth 中又添加了一列,它是来自另一个表的外键,如下所示:

MariaDB [ittresnamuda]> select * from tb_departement;
+----------------+------------------+-------+
| id_departement | nama_departement | alias |
+----------------+------------------+-------+
| 1 | ACCOUNTING | ACC |
| 2 | ARMADA | AMD |
| 3 | DIREKSI | DIR |
| 4 | EKSPOR | EXP |
| 5 | FINANCE | FIN |
| 6 | IMPORT | IMP |
| 7 | IT | IT |
| 8 | INVENTORY | INV |
| 9 | MARKETING | MKT |
| 10 | PERSUM | HRD |
| 11 | PURCHASING | PRC |
| 12 | OPERATION | OPS |
| 13 | LEGAL & CLAIM | LCL |
| 14 | SEKRETARIAT | SKRT |
+----------------+------------------+-------+
14 rows in set (0.00 sec)

这是 ion_auth 表:

MariaDB [ittresnamuda]> select id, username, email, id_departement from users LIMIT 20;
+----+---------------+--------------------------+----------------+
| id | username | email | id_departement |
+----+---------------+--------------------------+----------------+
| 1 | administrator | admin@admin.com | NULL |
| 5 | Dzil | dzil@tresnamuda.co.id | 1 |
| 19 | David | david_vl@indo.net.id | 3 |
| 20 | Emmy | emmy@indo.net.id | 5 |
| 21 | Hendrik | hl_kong@indo.net.id | 3 |
| 22 | ATaufiq | taufik@tresnamuda.co.id | 1 |
| 23 | Awal | awal@tresnamuda.co.id | 1 |
| 24 | Riana | riana@tresnamuda.co.id | 1 |
| 25 | Nugroho | accjkt@tresnamuda.co.id | 1 |
| 26 | Dudung | accjkt@tresnamuda.co.id | 1 |
| 27 | Farida | accjkt@tresnamuda.co.id | 1 |
| 28 | Nita | accjkt2@tresnamuda.co.id | 1 |
| 29 | Rayen | accjkt2@tresnamuda.co.id | 1 |
| 30 | Taka | accjkt@tresnamuda.co.id | 1 |
| 31 | Anjar | accjkt2@tresnamuda.co.id | 1 |
| 32 | Toni | accjkt@tresnamuda.co.id | 1 |
| 33 | Sukardi | sukardi@tresnamuda.co.id | 2 |
| 34 | Tiur | tiur@tresnamuda.co.id | 2 |
| 35 | Yuti | amdjkt@tresnamuda.co.id | 2 |
| 36 | Erfin | erfin@tresnamuda.co.id | 2 |
+----+---------------+--------------------------+----------------+

一组 20 行(0.00 秒)

如何使用 ion_auth 事件记录获取 name_departement 和别名?

最佳答案

使用钩子(Hook),您可以在调用 ion_auth 的 users 方法之前修改数据库查询,因此它将与您的表连接,如下所示:

class MyController extends CI_Controller {

// callback function to add join to db before call users method
public function prepare_user_list() {
$this->db->join('tb_departement','tb_departement.id_departement = ' . 'users.id_departement','inner');
}

public function index($group_id = NULL) {
$before_head = $this->load->view('admin/users/v_before_head', '', TRUE);
$before_body = $this->load->view('admin/users/v_before_body', '', TRUE);

$this->data['page_title'] = 'Users';
$this->data['before_head'] = $before_head;
$this->data['before_body'] = $before_body;
// subscribe for the users event
$this->ion_auth->set_hook('users', 'prepare_user_list', $this, 'prepare_user_list', array());
// then query the users
$this->data['users'] = $this->ion_auth->users($group_id)->result();
$this->render('admin/users/v_list_users');
}
}

关于mysql - ion_auth 与另一个表连接的事件记录/方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36325341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com