I've created a function which withdraw the user data from the database:
function user()
{
$user_id = $this->ci->session->userdata('user_id');
if (!is_null($user = $this->ci->users->get_user_by_id($user_id, TRUE))) {
return $this->ci->users->get_user($user_id); //model
}
return FALSE;
}
I'm using it like this in any controller:
$this->tank_auth->user()->field
.
Its not convenient for me, so what I need to do, to get the user data like this?
$this->user->field
or $this->tank_auth->user->field
.
My second question, regarding the above function is this function:
function is_admin()
{
if ( $this->user()->who )
{
return $this->user()->who === "ADMIN";
}
return FALSE;
}
It does throw error:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/Tank_auth.php
Line Number: 335
(Line 335 is if ( $this->user()->who )
).
Why does this happend? Both functions are located in the tank_auth's library, so its supposed to work fine, but it doesnt.
I'll appreciate any help attempt.