Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple redirect in Symfony2 by changing a query string parameter, NOT route related

Tags:

php

symfony

This should be simple, and I've been searching all over Google, but I keep coming up with 'route' related advice.

I just want to perform a redirect to the same page and modify one of the query string parameters (either to clear one or set one).

I can't see how to do this anywhere.

An option could be to completely generate the URL manually and use this I guess, but that doesn't seem a very good method:

$this->router->generate("http://domain.com?a=1")
like image 602
user2143356 Avatar asked Mar 17 '13 17:03

user2143356


1 Answers

I hope I understand what you intend to do... In your controller (?) use

$this->generateUrl(
    $request->attributes->get('_route'),
    array_merge(
        $request->query->all(),
        array('param' => 'val') // change the param
    )
);

to generate the url.

like image 199
Federkun Avatar answered Nov 12 '22 10:11

Federkun