How to get the full URL of a Drupal page?(如何获取 Drupal 页面的完整 URL?)
问题描述
我需要在 Drupal 站点中获取当前页面的 URL.它是什么内容类型无关紧要 - 可以是任何类型的节点.
I need to be grabbing the URL of the current page in a Drupal site. It doesn't matter what content type it is - can be any type of node.
我不是在寻找主题的路径、基本网址或 Drupal 的 get_destination.我正在寻找一个函数或变量,它可以为我提供以下完整信息:
I am NOT looking for the path to theme, or the base url, or Drupal's get_destination. I'm looking for a function or variable that will give me the following in full:
http://example.com/node/number
无论有没有(更有可能)http://
.
Either with or without (more likely) the http://
.
推荐答案
drupal_get_destination() 有一些内部代码指向正确的位置来获取当前的内部路径.要将该路径转换为绝对 URL,url() 函数应该执行以下操作诡计.如果传入 'absolute' 选项,它将生成完整的 URL,而不仅仅是内部路径.它还将为当前路径交换任何路径别名.
drupal_get_destination() has some internal code that points at the correct place to getthe current internal path. To translate that path into an absolute URL, the url() function should do the trick. If the 'absolute' option is passed in it will generate the full URL, not just the internal path. It will also swap in any path aliases for the current path as well.
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
$link = url($path, array('absolute' => TRUE));
这篇关于如何获取 Drupal 页面的完整 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取 Drupal 页面的完整 URL?


基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- HTTP 与 FTP 上传 2021-01-01