德鲁帕尔。从当前 url 获取路径别名,无需安装文件夹参数

发布于 2024-09-04 13:12:30 字数 213 浏览 6 评论 0原文

我想检索当前页面路径别名,而不需要安装的文件夹参数。 我正在使用:

drupal_get_path_alias(request_uri())

但这会返回安装/任何/实际/路径,并且我只想检索实际/路径,无论安装/什么 是。

提前致谢 :)

I'd like to retrieve the current page path alias without the installation's folder arguments.
I'm using:

drupal_get_path_alias(request_uri())

But this returns installation/whatever/actual/path and I want to retrieve the actual/path only no matter what installation/whatever is.

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

相思碎 2024-09-11 13:12:30

找到了。这实际上是两种建议的结合:

$current_path = drupal_get_path_alias($_GET["q"]);

不过还是谢谢。


更新:以前的解决方案并不总是有效

有人建议使用替代方法:

str_replace(base_path(), '', drupal_get_path_alias(request_uri(), 1));

但是,有没有办法在不使用稍微昂贵的 str_replace 的情况下做同样的事情?

谢谢

Found it. It was actually a mix of both suggestions:

$current_path = drupal_get_path_alias($_GET["q"]);

Thanks though.


Update: the previous solution doesn't always work

Someone suggested using an alternative method:

str_replace(base_path(), '', drupal_get_path_alias(request_uri(), 1));

But, is there any way of doing the same without using the slightly expensive str_replace?

Thanks

烧了回忆取暖 2024-09-11 13:12:30

您所在节点的路径?

http://api.drupal.org/api/function/drupal_get_path_alias/6

if ($node || (arg(0) == 'node' && arg(2) != 'edit')) {
   $system_path = 'node/'.arg(1);
   $current_path = drupal_get_path_alias($system_path);
}

该代码将在节点页面上触发并告诉您页面别名。

有关更多信息,您可以转储 $_GET 并查看“q”查询字符串值。

The path of the node you are on?

http://api.drupal.org/api/function/drupal_get_path_alias/6

if ($node || (arg(0) == 'node' && arg(2) != 'edit')) {
   $system_path = 'node/'.arg(1);
   $current_path = drupal_get_path_alias($system_path);
}

That code will fire on node pages and tell you the page alias.

For more information, you can dump out $_GET and look at the 'q' query string value.

拥抱没勇气 2024-09-11 13:12:30

也许您可以像这样使用base_path()和str_replace:

str_replace (base_path(), '', drupal_get_path_alias(request_uri()), 1);

base_path保存在数据库中。

Maybe you can use base_path() and str_replace like this :

str_replace (base_path(), '', drupal_get_path_alias(request_uri()), 1);

The base_path is saved in the database.

烧了回忆取暖 2024-09-11 13:12:30
$current_page_url = drupal_get_path_alias( implode( '/', arg() ) );

也有效

$current_page_url = drupal_get_path_alias( implode( '/', arg() ) );

also works

追风人 2024-09-11 13:12:30

您尝试过$_GET['q']吗?

Have you tried $_GET['q']?

〆凄凉。 2024-09-11 13:12:30

我倾向于获取完整的 url,以避免当 base_path() 不仅仅是“/”时出现的任何问题。

$url = (($_SERVER['HTTPS'])?"https://":"http://")  .  $_SERVER['HTTP_HOST'] . url($_GET['q']);

或者更简单地说:

$url = url($_GET['q'], array('absolute'=>true));

I tend to plump for the full url instead to avoid any problems that arise when base_path() isn't just '/'.

$url = (($_SERVER['HTTPS'])?"https://":"http://")  .  $_SERVER['HTTP_HOST'] . url($_GET['q']);

or even more simply:

$url = url($_GET['q'], array('absolute'=>true));
執念 2024-09-11 13:12:30

最快的解决方案。

substr(drupal_get_path_alias(request_uri(), 1), strlen(base_path()));

将其传递到参数

$arg =explode('/', substr(drupal_get_path_alias(request_uri( ), 1), strlen(base_path())));

Fastest solution.

substr(drupal_get_path_alias(request_uri(), 1), strlen(base_path()));

To pass it into an argument

$arg = explode('/', substr(drupal_get_path_alias(request_uri(), 1), strlen(base_path())));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文