1

I have a rendering problem. enter image description here

This problem occurs once as I want to put inside a database the content which I have from the frontend. I am obviously generating the command in a class called AppTriggerBuildCommand, but as described in the image the problem occurs once the code reaches this for example:

{{ render(controller('AppBundle:Menu:footerLarge', { 'language': language }  )) }}

inside the page.html.twig .

  [Twig_Error_Runtime]                                                                                                                 
  An exception has been thrown during the rendering of a template ("Rendering a fragment can only be done when handling a Request.").  


Exception trace:
 () at /var/www/html/iclei/src/AppBundle/Resources/views/page.html.twig:23
 Twig_Template->displayWithErrorHandling() at /var/www/html/iclei/vendor/twig/twig/lib/Twig/Template.php:366
 Twig_Template->display() at /var/www/html/iclei/vendor/twig/twig/lib/Twig/Template.php:374
 Twig_Template->render() at /var/www/html/iclei/vendor/twig/twig/lib/Twig/Environment.php:289
 Twig_Environment->render() at /var/www/html/iclei/src/AppBundle/Command/AppTriggerBuildCommand.php:69
 AppBundle\Command\AppTriggerBuildCommand->pageAction() at /var/www/html/iclei/src/AppBundle/Command/AppTriggerBuildCommand.php:38
 AppBundle\Command\AppTriggerBuildCommand->execute() at /var/www/html/iclei/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:242
 Symfony\Component\Console\Command\Command->run() at /var/www/html/iclei/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:861
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/iclei/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:193
 Symfony\Component\Console\Application->doRun() at /var/www/html/iclei/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:83
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/iclei/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
 Symfony\Component\Console\Application->run() at /var/www/html/iclei/app/console:27

I have tried both of the solutions suggested in the other. Once I have tried to rebuild bootstrap.php it just doesn't change a thing. This is inside the

/var/www/html/iclei/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php

And the other we can find it in here:

/var/www/html/iclei/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php

Could someone help me to get over this ?

FortuneSoldier
  • 502
  • 3
  • 21
  • Can you please post the debug output as code, not as image? – lxg Feb 20 '18 at 09:05
  • Possible duplicate of [Updating Symfony 2.4 : "Rendering a fragment can only be done when handling a Request."](https://stackoverflow.com/questions/21684218/updating-symfony-2-4-rendering-a-fragment-can-only-be-done-when-handling-a-re) – goto Feb 20 '18 at 09:12
  • I have tried both of the solutions. By this I mean rebuilding bootstrap.php and "refactoring" the Request object. None of those works. – FortuneSoldier Feb 20 '18 at 09:15

1 Answers1

1

You should create a request in your command and add it to the request stack

$r = new Request();
$r->setLocale('en');
$container->set('request', $r, 'request');
$container->get('request_stack')->push($r);
goto
  • 7,908
  • 10
  • 48
  • 58