Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP恢复完整URL drupal 8_Php_Drupal_Drupal 8 - Fatal编程技术网

PHP恢复完整URL drupal 8

PHP恢复完整URL drupal 8,php,drupal,drupal-8,Php,Drupal,Drupal 8,我在Drupal8网站上工作。在一个页面中,我有一个PHP块,其中包含一个带有GET方法的表单 在接收信息的页面中,我有一个URL,看起来像site/page?param1=value1¶m2=value2。我需要获得值2 我尝试了很多解决方案,但没有找到解决方案: $_GET['id']; // returns : null \Drupal::service('path.current')->getPath(); // returns : '/node/4' $_SERVER

我在Drupal8网站上工作。在一个页面中,我有一个PHP块,其中包含一个带有GET方法的表单

在接收信息的页面中,我有一个URL,看起来像
site/page?param1=value1¶m2=value2
。我需要获得值2

我尝试了很多解决方案,但没有找到解决方案:

$_GET['id'];
// returns : null

\Drupal::service('path.current')->getPath();
// returns : '/node/4'

$_SERVER['PHP_SELF'];
// returns : 'site/page'

$_SERVER['REQUEST_URI'];
// returns : 'site/page'

$_SERVER['argv'];
// returns : null

$_SERVER['HTTP_REFERER'];
// returns : 'http://site/node/4/edit'

\Drupal::request()->query->all();
// returns : array (size=0) empty

$path = \Drupal::request()->getpathInfo();
// returns : '/page'

\Drupal::request()->getRequestUri();
// returns : 'site/page'

\Drupal::request()->attributes->get('_system_path');
// returns : null

\Drupal::service('path.alias_manager')->getAliasByPath($current_path);
// returns : '/page'

$_SERVER['QUERY_STRING'];
// returns : ''

\Drupal::destination()->getAsArray();
// returns : 'site/page'

有人能帮我找到URL中的值2吗?

您可以使用多种服务检索URL参数,例如:

  • 请求栈
  • 路径电流
  • 当前路径匹配
这里我向您展示了如何使用
请求栈从
参数2
获取
值2

// Initialize the service.
$requestStack = \Drupal::service('request_stack');

// Get your Master Request.
$masterRequest = $requestStack->getMasterRequest();

// Get the value from a GET parameter.
$value = $masterRequest->query->get('param2');

进一步说:

  • 不要使用静态调用,例如
    \Drupal::service('request_stack')但将服务注入到块中。看
  • 理解其中的区别

希望它能帮助你

$value = \Drupal::request()->query->get('param2');

应该能做到这一点。

当我尝试这一点时,我得到了一个“空”。我认为问题出在表格上,我会尝试看看这个。谢谢。真正的网址是什么?你能在这里加上你的表格代码吗?您还可以尝试使用
CurrentRequest
而不是
MasterRequest
。例如,
$request=$requestStack->getCurrentRequest()如果有效,则您处于子请求中,请签出我为您提供的关于请求的链接。