PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 12, 2022

[FIXED] How to get query string in Symfony 4

 May 12, 2022     php, php-7.2, request, symfony, symfony4     No comments   

Issue

I am trying to access the query string parameters in Symfony 4

namespace App\Controller;

use Symfony\Component\HttpFoundation\RequestStack;

class Home extends Controller {

    private $request;

    public function __construct(RequestStack $request){

        $this->request = $request;
    }

    public function getQueryString(){

       $req = $this->request->getCurrentRequest();

       print_r($req); // see all the request data

       // $req -> grab the query parameters
       // return query parameters
    }
}

I am using RequestStack and able to see a bunch of request data when I print the result of getCurrentRequest() (including the query parameters I need), but most of the methods are private and I am not able to access them.

How does one go about getting the request URL components (including query parameters) in Symfony?


Solution

For GET query:

$this->request->getCurrentRequest()->query->get('name_query');

For POST query:

$this->request->getCurrentRequest()->request->get('name_query');


Answered By - Imanali Mamadiev
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing