Reputation: 1707
I want to use redirect in symfony to generate a url and at the same time I want to make a variable 'levels', accessible in the twig template but it does not seem to be working for me. here is the code:
return $this->redirect($this->generateUrl('show_admin_panel'), array('levels' => $levels));
I got this error: The HTTP status code "1" is not valid.
and if I use this:
return $this->redirect($this->generateUrl('show_admin_panel', array('levels' => $levels) ) );
I get this error: Variable "levels" does not exist in AUIAraBundle:Admin:admin_panel.html.twig at line 10
this is the code in the twig template:
{% for level in levels %}
<a href="{{ path('list_books',{'level_id': level.id}) }}"><li>{{level.letter}}</li></a>
{% endfor %}
Upvotes: 0
Views: 4505
Reputation: 2914
You don't need to query that variable 'level' in the action that redirects, just do:
return $this->redirect($this->generateUrl('show_admin_panel'));
Then in your controller linked to your 'show_admin_panel', make sure query that variable and pass it to the render method
//$level = something;
return $this->render('AUIAraBundle:Admin:admin_panel.html.twig',
array(
'levels' => $levels
)
);
}
Upvotes: 3