babour
babour

Reputation: 31

Remove GET variable symfony2

I am working on symfony 2.2 and I have an issue, when I try to delete a get variable such as message in this url : myurl?message=mymessage

It doesn't work.

public function myfunction1() { 
....    
return $this->redirect($this->generateUrl('_admin_credit', array("message" => $message))); // generate the url : myurl?message=mymessage
}

/**
* @Route("/credit", name="_admin_credit")
*/ 
public function getCreditAction($) { 
$request = $this->getRequest(); 

$message = $request->query->get('message'); // this works 
$request->query->remove('message'); // this work in the function but do not change the url

return $this->render('MyBundle:Admin:credit.html.twig', array(
                     'message' => $message
                ));  // still the same url : myurl?message=mymessage
}

Upvotes: 1

Views: 3464

Answers (1)

insertusernamehere
insertusernamehere

Reputation: 23580

$request->query->remove('message'); will remove the paramter from the ParameterBag only.

If you want to remove it from the URL you have to redirect to an URL without the parameter.

In Addition, if you want to keep the value of message, you can use a Flash Message to store it between two requests. This means: you can get the parameter, store it, redirect to another URL and recall the value once from the session.

Upvotes: 4

Related Questions