Object of type CodeIgniter\Session\Session is not callable |
Can anyone suggest why this error would occur?
I'm referencing a view parameter like this: Code: Object <?php if (!isset($session) || !$session('logged_in')): ?> The error is: Object of type CodeIgniter\Session\Session is not callable I recently upgraded to 4.3.3 but maybe I did something else also.
Simpler is always better
Yes, CodeIgniter\Session\Session is not callable.
What is the $session ?
(04-26-2023, 03:48 PM)kenjis Wrote: Yes, CodeIgniter\Session\Session is not callable. I passed it as a variable in a view function in a controller: PHP Code: print view('header', [ I fixed it by not doing that and used the session('logged_in') function in my view instead. Probably a better way to do it anyway. I have another application where I do the same thing and it does not give me this "session is not callable" error. I don't know what is different, both are using 4.3.3.
Simpler is always better
$this->session is a Session object. session() is the wrapper function for the shared Session object.
See https://codeigniter4.github.io/CodeIgnit...ssion-data
(04-27-2023, 03:42 AM)kenjis Wrote: $this->session is a Session object. session() is the wrapper function for the shared Session object. I know but why is referencing $this->session in a view file giving me the Session not callable error?
Simpler is always better
It seems you don't understand the difference between object and function clearly.
These are different: PHP Code: $session('logged_in') or $this->session('logged_in')
I know the difference.
$this->session is not a function. It is the session object. I have a session variable in my controller. I'm using it as a param of the view() function. e.g print view('myview', ['session' => $this->session]); It is giving me an error 'Session is not callable'. I've been doing this for many years a zillion times. It now no longer works. Something is screwed up.
Simpler is always better
(04-30-2023, 12:46 PM)donpwinston Wrote: I know the difference. Maybe composer setup is hosed. Don't have the problem in another app on another server where I do the same thing.
Simpler is always better
Your PHP is defective.
The Session class has never been Invokable. This means that your code could not work in principle.
(05-01-2023, 04:36 PM)iRedds Wrote: Your PHP is defective. ??? print view('my view', ['session' => session()]); myview.php ... <p><?= $session->xyz ?></p> ... So the proper way to access session data in a CI view is to use the session() function or fetch the session data into another variable and pass that to the view? I don't see why it matters. This has been working in CI4 for many years.
Simpler is always better
|
Welcome Guest, Not a member yet? Register Sign In |