德鲁帕尔。从当前 url 获取路径别名,无需安装文件夹参数
我想检索当前页面路径别名,而不需要安装的文件夹参数。 我正在使用:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
找到了。这实际上是两种建议的结合:
不过还是谢谢。
更新:以前的解决方案并不总是有效
有人建议使用替代方法:
但是,有没有办法在不使用稍微昂贵的 str_replace 的情况下做同样的事情?
谢谢
Found it. It was actually a mix of both suggestions:
Thanks though.
Update: the previous solution doesn't always work
Someone suggested using an alternative method:
But, is there any way of doing the same without using the slightly expensive str_replace?
Thanks
您所在节点的路径?
http://api.drupal.org/api/function/drupal_get_path_alias/6
该代码将在节点页面上触发并告诉您页面别名。
有关更多信息,您可以转储 $_GET 并查看“q”查询字符串值。
The path of the node you are on?
http://api.drupal.org/api/function/drupal_get_path_alias/6
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.
也许您可以像这样使用base_path()和str_replace:
base_path保存在数据库中。
Maybe you can use base_path() and str_replace like this :
The base_path is saved in the database.
也有效
also works
您尝试过
$_GET['q']
吗?Have you tried
$_GET['q']
?我倾向于获取完整的 url,以避免当 base_path() 不仅仅是“/”时出现的任何问题。
或者更简单地说:
I tend to plump for the full url instead to avoid any problems that arise when base_path() isn't just '/'.
or even more simply:
最快的解决方案。
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())));