0

I want to save complete model in session, so I can use data easily in entire application.

After successful login in application I am saving model in session and session save in database in ci_session table.

Code I tried:

$loginSuccess = $this->login_model->doLogin($username, $password);
if($loginSuccess) {
    $this->login_model->initialize();   // this will set value in private variable
    $serializelogin = serialize($this->login_model);
    $this->session->set_userdata('userprofile', $serializelogin);
}

This code gives me an error:

Error Number: 2006

MySQL server has gone away

Update: I change user_data column of table ci_session from text to longtext

Rahul Dadhich
  • 1,213
  • 19
  • 32
  • sessions aren't really meant for this. i think you are optimizing or attempting to before determining if there are any issues. – Alex Oct 15 '18 at 13:08

1 Answers1

0

U need to start by creating a session.

//Destroy old session
$this->session->sess_destroy();

//Create a fresh, brand new session
 $this->session->sess_create();

 //Set session data
$this->session->set_userdata($row);

Basically $row is an array. $row = $serializelogin->row_array();

or

$this->session->set_userdata(array('active_flag' => false, 'active_status' => 0));

make sure the data which has been returned from the model is in row_array format.

Abhilash Balaji
  • 76
  • 2
  • 14