Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By jozo.starosta on
I am running Drupal 8.2.4
I created a node (page) with PHP text format, say node/999:
$getHttpHost= \Drupal::request()->getHttpHost();
echo("getHttpHost=[".$getHttpHost."]<br>");
$getClientIp= \Drupal::request()->getClientIp();
echo("getClientIp=[".$getClientIp."]<br>");
$getScriptName= \Drupal::request()->getScriptName();
echo("getScriptName=[".$getScriptName."]<br>");
When I try http://mysite.ca/node/999
I get host, IP and script as expected.
When I try
$getRequestUri= \Drupal::request()->getRequestUri();
echo("getRequestUri=[".$getRequestUri."]<br>");
$getQueryString= \Drupal::request()->getQueryString();
echo("getQueryString=[".$getQueryString."]<br>");
$query = \Drupal::request()->query->all();
echo("query=[");
print_r($query );
echo("]<br>");
echo("<br>");
$request= \Drupal::request()->request->all();
echo("request=[");
print_r($request);
echo("]<br>");
echo("<br>");
and point the browser to
http://mysite.ca/node/999?par1=val1&par2=val2
I get:
getRequestUri=[/node/999]
getQueryString=[]
query=[Array ( ) ]
request=[Array ( ) ]
--------------
Why cannot I get $_GET parameters?
Thank you.
Comments
Help?
Can somebody recommend me where can I find an answer to my question?