0
votes

I receive an error when I change pages if I am impersonated as another user in Symfony2. It only happens when the route has additional parameters. There is no sign of route generation at the pointed line number.

Controller action

/**
 * @Route("/member/{id}", name="member_page")
 * @Template()
 */
public function memberAction($id)

Error

An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("slug") to generate a URL for route "member_page".") in members.html.twig at line 2.

3
How to you supply this slug to your template members.html.twig? - Jovan Perovic

3 Answers

2
votes

Do you have two routes with the same name?

Watch your routing.yml file or the class annotation, maybe you have defined a prefix with slug parameter.

0
votes

If the "slug" parameters is not necessary, provide a default for that as NULL. Here is an example

message_edit:
    pattern:  /edit/{slug}
    defaults: { _controller: CommunicationBundle:Default:edit, slug: null }
0
votes

Thanks for the answers, but there was something else going on: The template was extending another template in which the bug could be found. Therefor an incorrect linenumber was displayed in the eror message. After setting up a smaller test environment I could replicate the problem. It was an anchor to exit impersonation which I wanted to redirect to the current page, but was obviously missing the parameters of the current page:

<a href="{{ path( 'app.request.attributes.get('_route')', {'_switch_user': '_exit'}) }}">Stop impersonation</a>

I fixed it for now by just using the named 'home' route.