0

My app is PHP / CodeIgniter / TankAuth.

I have in my database an account balance of sorts, and I want to display this account balance on my app's pages. So I've got in all nicely working, holding the balance in the session data.

The balance only changes on login, under certain conditions. So in the tank_auth components, there is a controller, a library etc. The flow is that the Auth controller login calls on the Tank_auth library login function, where the session is created, and then calls on the model to update the login info (IP address, last login etc.) That's all out the box.

So I've extended the session aspects in the library, adding my own user data 'account_balance'. which is fine, but the problem is when the balance changes, my session data is "behind", and I'm really struggling to work out how to update it.

First attempt is to simply try and update the session information after I've updated my database, in the users model (the stock standard Tank_Auth model). It doesn't work, giving me an error.

After some experimenting get this, I realise that I don't understand what this is about. :

echo  $this->session->userdata('ip_address');      //works fine - no errors
echo  $this->ci->session->userdata('ip_address');  //fail

The Tank_auth modules (library, controllers, models, etc) sometimes refer to ci->sessions and sometimes not, but it uses both.

In the class constructors, it also uses:

$this->ci =& get_instance();  //in the library
$ci =& get_instance();        //in the model

I'm getting 2 errors :

  • Message: Undefined property: Auth::$ci
  • Trying to get property of non-object

I was under the impression that one would use CI sessions, because it has some nice features, or not if one doesn't want them. But using both.....?

What am I missing?

Thanks in advance.

Maxcot
  • 1,513
  • 3
  • 23
  • 51

1 Answers1

0
//if you are using get_instance() in codeigniter then user following syntax to write code:
$ci =& get_instance();
echo $ci->session->userdata("ip_address");
  • What I'm trying to understand is the difference between $this->session and $this->ci->session – Maxcot Jul 19 '13 at 07:27
  • Normally within our controller functions we call any of the available CodeIgniter functions using the $this construct and get_instance function returns the CodeIgniter super object, so either we use $this construct or the super object variable define by & get_instance() – Girish Kumar Sinha Jul 19 '13 at 07:34
  • In the CodeIgniter user-guide, it says that the CI session class does NOT use native PHP sessions. So if "$this->ci->session" is the CodeIgniter Session class, and "$this->session" is the native PHP session class, then this Tank_Auth library, is in fact using both.... right? Why would one do that? – Maxcot Jul 19 '13 at 07:45