-3

I'm attempting to remove the query strings parameters displayed in the browser url:

https://foo.bar?key=value

Is it possible to modify GET (query strings) parameters at refresh in Symfony controller without redirection? For example:

public function testAction(Request $request): Response
{
    $request->query->get('test'); //output: query string parameter named test

    //some way to change the GET parameters

    return new Response();
}

How to remove 'test' parameter on refresh? Obviously, I can remove the parameter from a request, but it doesn't affect the response. I believe problem is that don't have a deep understanding of how is request passed to response in Symfony.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Jakub Mróz
  • 11
  • 1
  • 4
  • what's wrong with redirections? IMO a redirection would be the best choice, since you redirect the requester to another route – Cid Nov 16 '21 at 09:15
  • that would make a mess in my code. Actually I don't want to change the route, but only remove this parameter, if exist. – Jakub Mróz Nov 16 '21 at 09:17
  • This [Symfony doc article](https://symfony.com/doc/current/components/http_kernel.html#the-workflow-of-a-request) might help with understanding the Request/Response workflow. Understanding the workflow is really the key to using the framework effectively. I don't understand what you are trying to do but it's possible that a kernel request listener might suit your needs. – Cerad Nov 16 '21 at 13:19
  • What are you doing in the response that contains the request querystring data? Are you attempting to remove the querystring params displayed in the browser URL? If so, Symfony cannot change the browser URL without a redirect, since the browser sends the request with the querystring params from the client-side and the Symfony response is sent back for that request from the server-side. To remove the client-side querystring params without a redirect you would need to use [Javascript](https://stackoverflow.com/q/10700937/1144627) – Will B. Nov 16 '21 at 17:03
  • @Cerad - I read this docs before, but it didn't gave me an answer. – Jakub Mróz Nov 17 '21 at 07:52
  • @WillB. Thank you for anwser, maybe put is as a official answer? Because that's exactly what I was asking about. – Jakub Mróz Nov 17 '21 at 07:54
  • Thanks @JakubMróz Your question should be marked as a duplicate of the [How can I remove the query string from the url after the page loads?](https://stackoverflow.com/q/10700937/1144627) question I linked to, Upvote a helpful answer there instead. Since the rest of the information is related to Client/Server side procedures, unrelated to the Symfony request/response specifically, any answer I could provide would be low quality at best, not really providing a solution other than reference material. – Will B. Nov 17 '21 at 15:13
  • @WillB. The answer would be helpful, because I was asking is there possibility to edit query string on server side, while refresh page, in controller for example, like in the question. I will answer myself :) – Jakub Mróz Nov 18 '21 at 08:06

1 Answers1

0

You can modify query string (GET parameters) two ways:

  1. Using JavaScript (How can I remove the query string from the url after the page loads?)
  2. By redirection
Jakub Mróz
  • 11
  • 1
  • 4