2016-03-31 8 views
0

ich jetzt benutze ion_auth, In ion_auth, können wir alle Datensatz wie folgt aus:ion_auth aktiven Datensatz/Methode, die mit einer anderen Tabelle verbunden

-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'); 
} 

Mein Fall ist, ich eine weitere Spalte in der Standardtabelle ion_auth mit dem Namen id_departement hinzugefügt, die ein Vorgängerschlüssel aus einer anderen Tabelle ist:

Dies ist die ion_auth Tabelle:

MariaDB [ittresnamuda]> select id, username, email, id_departement from users LIMIT 20; 
+----+---------------+--------------------------+----------------+ 
| id | username  | email     | id_departement | 
+----+---------------+--------------------------+----------------+ 
| 1 | administrator | [email protected]   |   NULL | 
| 5 | Dzil   | [email protected] |    1 | 
| 19 | David   | [email protected]  |    3 | 
| 20 | Emmy   | [email protected]   |    5 | 
| 21 | Hendrik  | [email protected]  |    3 | 
| 22 | ATaufiq  | [email protected] |    1 | 
| 23 | Awal   | [email protected] |    1 | 
| 24 | Riana   | [email protected] |    1 | 
| 25 | Nugroho  | [email protected] |    1 | 
| 26 | Dudung  | [email protected] |    1 | 
| 27 | Farida  | [email protected] |    1 | 
| 28 | Nita   | [email protected] |    1 | 
| 29 | Rayen   | [email protected] |    1 | 
| 30 | Taka   | [email protected] |    1 | 
| 31 | Anjar   | [email protected] |    1 | 
| 32 | Toni   | [email protected] |    1 | 
| 33 | Sukardi  | [email protected] |    2 | 
| 34 | Tiur   | [email protected] |    2 | 
| 35 | Yuti   | [email protected] |    2 | 
| 36 | Erfin   | [email protected] |    2 | 
+----+---------------+--------------------------+----------------+ 

20 rows in set (0.00 sec)

Wie kann ich name_departement und alias aktiven Datensatz mit ion_auth?

Antwort

1

Mit Haken können Sie die DB-Abfrage ändern, bevor Sie die Benutzer-Methode des ion_auth nennen, so wird es mit Ihrem Tisch kommen, wie folgt aus:

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'); 
    } 
} 
Verwandte Themen