[TwigBundle] added request and session as global variables

* removed the "_view" variable from templates
 * removed the "flash()" function (now available from the session directly {{ session.flash('notice') }})
This commit is contained in:
Fabien Potencier 2011-01-04 13:59:16 +01:00
parent 0e487cdda6
commit b60d254be2
3 changed files with 9 additions and 7 deletions

View File

@ -52,6 +52,11 @@ class Engine extends BaseEngine
}
}
public function getContainer()
{
return $this->container;
}
/**
* Renders a view and returns a Response.
*

View File

@ -74,7 +74,6 @@ class TemplatingExtension extends \Twig_Extension
'url' => new \Twig_Function_Method($this, 'getUrl'),
'path' => new \Twig_Function_Method($this, 'getPath'),
'asset' => new \Twig_Function_Method($this, 'getAssetUrl'),
'flash' => new \Twig_Function_Method($this, 'getFlash'),
);
}
@ -93,11 +92,6 @@ class TemplatingExtension extends \Twig_Extension
return $this->container->get('templating.helper.assets')->getUrl($location);
}
public function getFlash($name, $default = null)
{
return $this->container->get('request')->getSession()->getFlash($name, $default);
}
/**
* Returns the token parser instance to add to the existing list.
*

View File

@ -37,7 +37,10 @@ class Renderer extends BaseRenderer
*/
public function evaluate(Storage $template, array $parameters = array())
{
$parameters['_view'] = $this->engine;
// cannot be set in the constructor as we need the current request
$request = $this->engine->getContainer()->get('request');
$this->environment->addGlobal('request', $request);
$this->environment->addGlobal('session', $request->getSession());
return $this->environment->loadTemplate($template)->render($parameters);
}