i have a problem when i want to get $_SESSION[\'session\'];
in twig template using slim micro Framework.
this is my code :
I'm using Slim and Twig as well. My class:
class twigView extends Slim_View {
public function render( $template) {
$loader = new Twig_Loader_Filesystem($this->getTemplatesDirectory());
$twig = new Twig_Environment($loader);
$twig->addGlobal("session", $_SESSION);
return $twig->render($template, $this->data);
}
}
As you can see I've added addGlobals
. Now it works as it should and I can use {{session.user_id}}
and so.
A part of my index.php:
require './lib/twigView_class.php';
require_once './lib/Twig/Autoloader.php';
require './lib/Paris/idiorm.php';
require './lib/Paris/paris.php';
Twig_Autoloader::register();
I hope it will help you.
But is it safe to use 'global' in Twig ?