Welcome Guest, Not a member yet? Register   Sign In
How simply work session ?
#1

Hello,

I try to use session() but I get this error :
{PHP internal code}   —  CodeIgniter\Debug\Exceptions->shutdownHandler ()

I want to set session globally in BaseController and simply use session() to set my session.

My session is working if I use php superglobal $_SESSION[] but impossible to use session().

Please give me the code to insert into BaseController, normally I can simply put code like this in my controller :

session('test')='my test';
echo session('test');

No ?

I'm lost trying many many thing !
Reply
#2

There's multiple way to get/set session data. Here's some examples, see the links for more details.

Adding session data: http://codeigniter.com/user_guide/librar...ssion-data
PHP Code:
$newdata = [
        'username'  => 'johndoe',
        'email'     => '[email protected]',
        'logged_in' => TRUE
];

$session->set($newdata);

$session->set('some_name''some_value'); 


Retrieving session data: http://codeigniter.com/user_guide/librar...ssion-data
PHP Code:
$item session('item');
$item $session->get('item'); 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

What is the actual error message? What you are showing is only the backtrace.
Reply
#4

Use the session helper method like this works on all session methods using chaining.

PHP Code:
// seesion helper using method chaining.
session('item');
session()->get('item');
session()->set($array);
session()->has('some_name');
session()->remove('some_name'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB