We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to get all the variables and values from the session in Phalcon?

Why there is no info in the docs on how to display the complete session content with all the variables and values that it contains?

I tried something like this:

print_r($this->session);

but It gives me this:

Phalcon\Session\Adapter\Files Object ( [_uniqueId:protected] => [_started:protected] => 1 [_options:protected] => )

Which is not what I wanted.

I also tried:

print_r( $this->session->get() );

But I get this error: Wrong number of parameters



37.0k
edited Jul '14

I am getting this error :(

Fatal error: Call to undefined method Phalcon\Session\Adapter\Files::getIterator()

Can you paste your $di->set('session', ...) ?



37.0k
edited Jul '14
$di->set('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});

i know that session is working because this: print_r($this->session->get('auth-identity')); will output Array ( [id] => 14 [name] => admin [profile] => Administrators ) when I am logged in as admin.

But I just need to show everything in the session, not only auth-identity

It's strange. Files adapter extends getIterator method from parent class.

Can you check what you get from \Phalcon\Version::get()?

Ok, I checked this. getIterator method appears in 1.3.0.



37.0k

How to get all session in 1.2.6?

I think that $_SESSION variable should be works independent from version.



37.0k
edited Jul '14

print_r($_SESSION); die;

will give this errror:

Notice: Undefined variable: _SESSION

;(



5.2k
Accepted
answer

Get iterator also use $_SESSION global (https://github.com/phalcon/cphalcon/blob/phalcon-v1.3.0/ext/session/adapter.c#L678).

I see that needs add session_start(); outside any function, for example like this:

$di->set('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
session_start();

Better way is upgrade to newer version of PHP but this is quickier.



37.0k
edited Jul '14

Thanks, finally session_start(); outside of the function helped in my case. PHP 5.4, Phalcon 1.2.6 and print_r($_SESSION) works in controller.