In PHP we can loop the $_SESSION global variable to get all PHP session variables. But if I created Phalcon session variables how can I get all of them ?
|
Feb '16 |
3 |
975 |
0 |
Checked adapter soruce files, but i cannot find such method. Maybe it is intentional to not implement it?
However when storing data with Phalcon sessions the data is available in $_SESSIOn as well. So if you have a specific case to get all session data you can access it. Or even make your own session class with method like:
function getAll()
{
return $_SESSION;
}
I never needed to do something like you asked, but let's hope someone has fought with similar problem and will tell us :)
my Phalcon version is 2.0.8 , build date Sep 26 2015 16:24:18.
I setup session service in the public index.php file :
[code]<?php
use Phalcon\Loader; use Phalcon\DI\FactoryDefault; use Phalcon\Mvc\View; use Phalcon\Mvc\Application; use Phalcon\Mvc\Url as UrlProvider; use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; use Phalcon\Session\Adapter\Files as Session;
try {
// Register an autoloader
$loader = new Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new FactoryDefault();
// Start the session the first time when some component request the session service
$di->setShared('session', function () {
$session = new Session();
$session->start();
return $session;
});
...
//Handle the request
$app = new Application($di);
echo $app->handle()->getContent();
} catch(\Exception $e) { echo "Exception: ", $e->getMessage(); }
?>[/code]
I found the solution : I must call this code in order to synchronize Phalcon sessions and PHP session :
$di = \Phalcon\DI::getDefault();
$session = $di->getSession();
So Why should I call this code to synchronize Phalcon sessions and PHP sessions ?