Welcome Guest, Not a member yet? Register   Sign In
Global access to $session in controlers and modules
#1

According to: https://codeigniter.com/user_guide/libra...sions.html

I should be able to initialize i BasicController:
Code:
$session = \Config\Services::session($config);

and then use $session whenever i want, but if i am trying to use it in other controllers without problem, but i am getting: Undefined variable: session

I can initialize:
Code:
$this->session = \Config\Services::session();

and then use in other controllers: $this->session->. It works fine, but i would preffer to use $session-> (for reasons). I need to initialize it somewhere else or something?
Thread about my project that is using CodeIgniter:
Reply
#2

(This post was last modified: 02-03-2022, 05:25 PM by kenjis.)

It seems you need to learn PHP's variables and properties.

See
https://www.php.net/manual/en/language.v...basics.php
https://www.php.net/manual/en/language.v....scope.php
https://www.php.net/manual/en/language.o...erties.php
But the explanation in the PHP manual is not easy to understand.
Reply
#3

Intiallize it in the BaseController then use the session helper $session()->
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(02-03-2022, 05:14 PM)kenjis Wrote: It seems you need to learn PHP's variables and properties.

See
https://www.php.net/manual/en/language.v...basics.php
https://www.php.net/manual/en/language.v....scope.php
https://www.php.net/manual/en/language.o...erties.php
But the explanation in the PHP manual is not easy to understand.

Sorry, but this is a typical answer that doesn't help anyone.
Reply
#5

If a programmer can read and understand the PHP manual, it is the most precise resource.
It helps he/she a lot.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB