Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



20.5k
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', ...) ?



20.5k
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.



20.5k

How to get all session in 1.2.6?

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



20.5k
edited Jul '14

print_r($_SESSION); die;

will give this errror:

Notice: Undefined variable: _SESSION

;(



3.5k
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.



20.5k
edited Jul '14

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