2

What is the magento 2 equivalent of $_SERVER['QUERY_STRING']

I want to retrieve the full query string from the url and would like to do this using the framework's built in functions.

3

I was able to achieve this using the getServer() in the \Magento\Framework\HTTP\PhpEnvironment\Request class

public function __construct
(
    \Magento\Framework\HTTP\PhpEnvironment\Request $request,
)
{
    $this->request = $request;
}

public function execute()
{
    \Zend_Debug::dump($this->request->getServer('QUERY_STRING'));
    die;
}

If no argument is set, $this->request->getServer() will return complete $_SERVER array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.