Create, set and get the session in CodeIgniter 4
1 2 3 4 5 6 7 8 9 10 11 12 | protected $session; public function index() { $this->session = \Config\Services::session(); $this->session->set('view_data','Hi there I am from the session'); $page['view_data'] =$this->session->get('view_data'); // Normal way $page['session'] =$this->session; // Pass in the object echo view('test_session_view',$page); } |
In view, you have to call the session again where you want to get session
1 | $this->session = \Config\Services::session(); |