Home > Back-end >  How to use Session Library in codeigniter 4, i get some error when use the session library
How to use Session Library in codeigniter 4, i get some error when use the session library

Time:11-23

I want to use session library in codeigniter 4,i read the codeigniter 4 documentation. I set the session library in constructor function, but i get error like this

enter image description here

I have set up session library like this :

class Login extends BaseController
{
    protected $authModel;
    protected $session;

    public function __construct()
    {
        $this->session = \Config\Services::session();
        $this->session->start();
        $this->authModel = new AuthModel();
    }

and I set the session value on my controler like this :

  $userData = [
                'username'  => $result['result']['username'],
                'role_id'     => $result['result']['role_id'],
            ];

            $this->session->set($userData); // setting session data
            dd($this->session->get("username"));

But that's not working Please help me who knows the solution

CodePudding user response:

Edit your .env file and set:

app.sessionSavePath = '/tmp/ci4_session'
  • Related