简体   繁体   中英

Url query parameters becoming visibly encoded upon redirect - Symfony 2

I am attempting to persist my query parameters when redirecting to a new path with Symfony2 , however the method I am using appears to show encoded query parameters in the URL...

return $this->redirect(
    $this->generateUrl(
        'my_page_name',
        [
            'myVar' => $myVar,
            $request->query->all() 
            // I have also tried $request->getQueryString() with the same result...
        ]
    )
);

When sending an URL with query params such as

my-domain.com/some-page?var1=test&var2=test

I can visibly see the URL change in the browser on redirect to something resembling

my-domain.com/some-page?0var1%3Dtest%26var2%3Dtest

My question here is...

1) Does this affect the actual URL being navigated to 2) Is there any way in which I can stop this and keep the URL looking as it was entered?

It is encoding request parameters because you are passing whole array as parameter which in terms gets serialized, to avoid that you need to pass each parameter individually. This can be achieved by merging arrays.

So solution would look like :

return $this->redirect(
    $this->generateUrl(
        'my_page_name',
        array_merge(
            array(
                'myVar' => $myVar, 
                'myVar2' => $myVar2
            ),
            $request->query->all()
      ) 
    )
);

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