Search code examples
codeigniter-2

Codeigniter Session Class userdata?


i have some question in Codeigniter session class:

  1. whats different between these

    $this->session->all_userdata(); 
    $this->session->userdata
    

    both of them return array of all user data in ci session (cooke).

  2. and why this code is wrong:

    $this->session->userdata();
    

    but this one is correct:

    $this->session->userdata
    

    why?


Solution

  • for 1: $this->session->all_userdata(); is method to get CI-session's data $this->session->userdata is variable of CI-session's class, You shouldn't get session's data this way.

    for 2: $this->session->userdata(); is correct because this way You'll use setters-getters mechanism (read more here), $this->session->userdata is incorrect because You try to get data directly (read link above to get more info)