Welcome Guest, Not a member yet? Register   Sign In
Object of type CodeIgniter\Session\Session is not callable
#1

(This post was last modified: 04-26-2023, 02:23 PM by donpwinston.)

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
Reply
#2

Yes, CodeIgniter\Session\Session is not callable.
What is the $session ?
Reply
#3

(This post was last modified: 04-27-2023, 03:42 AM by donpwinston.)

(04-26-2023, 03:48 PM)kenjis Wrote: Yes, CodeIgniter\Session\Session is not callable.
What is the $session ?

I passed it as a variable in a view function in a controller:

PHP Code:
print view('header', [
 
'current' => 'register',
 
'title' => 'BNC New User Agreement',
 
'meta_desc' => 'Register here for electronic bankruptcy noticing or to establish a preferred address!',
 
'session' => $this->session,
 ]); 

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
Reply
#4

$this->session is a Session object. session() is the wrapper function for the shared Session object.
See https://codeigniter4.github.io/CodeIgnit...ssion-data
Reply
#5

(04-27-2023, 03:42 AM)kenjis Wrote: $this->session is a Session object. session() is the wrapper function for the shared Session object.
See https://codeigniter4.github.io/CodeIgnit...ssion-data

I know but why is referencing $this->session in a view file giving me the Session not callable error?
Simpler is always better
Reply
#6

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')
session('logged_in'
Reply
#7

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
Reply
#8

(04-30-2023, 12:46 PM)donpwinston Wrote: 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.

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
Reply
#9

Your PHP is defective.
The Session class has never been Invokable. This means that your code could not work in principle.
Reply
#10

(This post was last modified: 05-02-2023, 02:55 AM by donpwinston.)

(05-01-2023, 04:36 PM)iRedds Wrote: Your PHP is defective.
The Session class has never been Invokable. This means that your code could not work in principle.

???

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB