Thursday 29 November 2018

php - Silex redirect from Twig template

First, I know this is a horrible thing to do and should be done in controller logic only, but what I'm trying to do is create a custom redirect tag in Twig that fires a Silex redirect.



I have a custom node that outputs the following into the doDisplay template:



return $this->getEnvironment()->getExtension('silex')->getApp()->redirect('/', 301);


Basically this gets the Twig environment and the extension I created which has a getApp method which returns the Silex $app variable, which contains the redirect method.




But this only returns Array() to the screen. Any suggestions?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...