如何获取Drupal页面的完整网址? [英] How to get the full URL of a Drupal page?

查看:162
本文介绍了如何获取Drupal页面的完整网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要抓取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.

我不是寻找主题或基本URL或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://

推荐答案

drupal_get_destination()有一些内部代码指向正确的位置以获取当前的内部路径。要将该路径转换为绝对URL, url()功能应该招。如果传递的绝对选项将生成完整的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页面的完整网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆