I am creating a module and having some difficulty getting what to me seems to me general information.

For instance, I need to get information about the current node. I know you can use global $user, but I don't need user information, I need the node id for the current page so I can get taxonomy information for that particular node and do some of my own queries.

Comments

AjK’s picture

Method one:

if (arg(0) == 'node' && is_numeric(arg(1)) {
  $nid = arg(1);
}

Or, assuming you are starting from a MENU_CALLBACK or other menuing item that calls back then you'll have, for example 'path' => 'myfunc', 'callback' => '_myfunc', in the menu items array. Then, in _myfunc() do this.....

function _myfunc() {
  $args = func_get_args();

  // $args[0] will equal the url param passed.
}

So, in the above example, with the path :
myfunc/23 then $args[0] will be 23
myfunc/23/edit then $args[0] is 23, $args[1] is 'edit'

NitroPye’s picture

That's perfect. Did the trick. Putting that in my notes.