php 在 Drupal 7 中获取节点的 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8626653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:07:03  来源:igfitidea点击:

Getting the URL of a node in Drupal 7

phpdrupaldrupal-7

提问by Vishal Khialani

Goal: To send an email with a list of URLs generated from nodes.

目标:发送带有从节点生成的 URL 列表的电子邮件。

In my custom module I have managed to get the node id which the user wants and I now want to get the URL of each node to put into my email.

在我的自定义模块中,我设法获取了用户想要的节点 ID,现在我想获取每个节点的 URL 以放入我的电子邮件。

I searched the db and used google but I can't seem to find the right solution.

我搜索了数据库并使用了谷歌,但似乎找不到正确的解决方案。

It seems we need to construct the URL something like this:

看来我们需要像这样构造 URL:

<?php
global $base_url;
$link=$base_url."// few more parameters 

回答by Clive

You can use the url()function:

您可以使用该url()功能:

$options = array('absolute' => TRUE);
$nid = 1; // Node ID
$url = url('node/' . $nid, $options);

That will give you the absolute path (i.e. with http://example.com/in front of it), with the URL aliased path to the node page.

这将为您提供绝对路径(即在其前面带有http://example.com/),以及指向节点页面的 URL 别名路径。

回答by scotself

You can also try drupal_lookup_path('alias',"node/".$node->nid).

你也可以试试drupal_lookup_path('alias',"node/".$node->nid)

回答by Yuseferi

Also you can get it by

你也可以通过

   $path=drupal_get_path_alias('node/'.$nid);

回答by mattwith

You can also use the l()function.

您还可以使用l()函数。

  l(t('Link text'), 'node/123', array('options' => array('absolute' => TRUE)));

回答by manish

use

$node_url;

$node_url;

it will give you the current node url

它将为您提供当前节点 url