PHP恢复完整URL drupal 8
我在Drupal8网站上工作。在一个页面中,我有一个PHP块,其中包含一个带有GET方法的表单 在接收信息的页面中,我有一个URL,看起来像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
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()代码>如果有效,则您处于子请求中,请签出我为您提供的关于请求的链接。