Passing a session variable in a function to helper in codeigniter

Here is what I am trying to do. This is a function in the controller.

public function get_started() { if(test_login($this->session->all_userdata())) { $this->load->view('template'); } else { $this->load->view('error'); } } 

This is an auxiliary

 function test_login($sessdata) { if($sessdata->userdata('is_logged_in')) { return true; } else { return false; } } 

I entered is_logged_in as the session boolean variable. However, this does not work.

I can not find the error.

+8
php codeigniter
source share
1 answer

instead of passing the session data as a parameter to your assistant, you can access the session from the assistant itself, for example:

 function test_login() { $CI = & get_instance(); //get instance, access the CI superobject $isLoggedIn = $CI->session->userdata('is_logged_in'); if( $isLoggedIn ) { return TRUE; } return FALSE; } 

And the controller:

 public function get_started(){ if( test_login() ) { $this->load->view('template'); } else { $this->load->view('error'); } } 
+18
source share

All Articles