Reputation: 508
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 ?
Upvotes: 1
Views: 590
Reputation: 8162
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);
Upvotes: 1