简体   繁体   中英

Redirection in Symfony2

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 %}

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
                )
            );
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM