Vishal Khialani Vishal Khialani - 1 year ago 106
PHP Question

Getting the URL of a node in Drupal 7

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

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.

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:

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

Answer Source

You can use the url() function:

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download