T
T
tsifra2013-12-04 15:56:32
symfony
tsifra, 2013-12-04 15:56:32

How to render controller in twig template?

Today I upgraded to symfony 2.4 and ran into a code migration problem. Previously, this worked without problems. Now indexdata separately returns the desired results, but it is not possible to render it from the template of another controller

render(controller('BackendWorkorderBundle:Default:indexdata'))

Output error
LogicException: Rendering a fragment can only be done when handling a Request.

Tell me how to send to indexdata request or other ways to solve the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2013-12-04
@tsifra

We need context. Where does the code run from, from a console command? Give an example of the method that you call .... In general, this error can only be from the fact that there is no Request object

T
tsifra, 2013-12-04
@tsifra

Yes that's right. Understood. The call was from a twig template
{{ render(controller('BackendWorkorderBundle:Default:indexdata')) }} indexdata is the controller's action. The problem was the following.
I tried to get the $session in the action in the following way, which worked fine in 2.3.7

$request = $this->get('request');
$session = $request->getSession();

In 2.4 the code was adapted like this. And everything worked again.
Thank you very much for your participation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question