0

What is the right way to get all the data from the 'users' table in my database, using Tank Auth?

I tried it with just with $this->db->get('users');

But how do i get the data for the specific logged-in user? Do I have to use $this->tank_auth->get_user_id();?

Here's what I've tried:

function get_user_data()
{
    $id = $this->tank_auth->get_user_id();
    $this->db->where('id', $id);
    $users = $this->db->get('users');

    return $users->result();
}

I hope somebody can help me out with this.

Expedito
  • 7,771
  • 5
  • 30
  • 43
Kees Sonnema
  • 5,759
  • 6
  • 51
  • 106

1 Answers1

1

This code will get data about the current logged user.

In your controller:

$this->load->library('tank_auth');

if (!$this->tank_auth->is_logged_in()) {
    exit('no logged user');
} else {
    $user_id = $this->tank_auth->get_user_id();
    $user_data = $this->users->get_user_by_id($user_id,1);
}
Aurel
  • 3,682
  • 1
  • 19
  • 22
  • why do i get the error: A PHP Error was encountered Severity: Warning Message: Missing argument 2 for Users::get_user_by_id(), called in /var/www/vhosts/een-site-bouwen.nl/subdomains/kees/httpdocs/application/controllers/members.php on line 20 and defined Filename: tank_auth/users.php Line Number: 34 – Kees Sonnema Apr 23 '13 at 13:37
  • so how do i call the data in the views? – Kees Sonnema Apr 23 '13 at 13:41
  • $this->load->view('your_view.php', array('user_data' => $user_data)); – Aurel Apr 23 '13 at 13:44
  • I think it will help you if you look for tutorials of codeigniter basis. – Aurel Apr 23 '13 at 13:46
  • i know how to do it like $data['user_data'] but i forgot how to do it with just $user_data or something. – Kees Sonnema Apr 23 '13 at 13:46
  • $this->load->vars('user_data', $user_data); http://ellislab.com/codeigniter/user-guide/libraries/loader.html – Aurel Apr 23 '13 at 13:48
  • oh yeah. sorry for the dumb question. i'll accept your answer :) – Kees Sonnema Apr 23 '13 at 13:49