I'm making a module that will need to pass some wildcard arguments in a URL. Is there any way to do this without having to write a hook_menu function? In other words, is there a way for a custom function in a module to just grab these arguments and add their values to the $node variable?

Comments

baldwinlouie’s picture

you always have access to the url with the arg() function or the $_GET array. For example, if you have a url like such ?q=node/1234(clean url), /node/1234, you can use arg(1) to get the 1234 out of the url.

is that what you are looking for?

Baldwin Louie,
BitSprout LLC
http://www.bitsprout.net

perloe’s picture

That is so easy! Thanks so much!

TurtlePower’s picture

Is there any way I can access arguments when using a URL alias? For example, if my URL is /node/123/a1/a2, I can access the values of a1 and a2 with the arg() function, but if create a URL alias /myalias that maps to /node/123, I can't figure out how to get the arguments out of /myalias/a1/a2 (this url just gives a 404 error).

Thanks.

TurtlePower’s picture

I found the answer to my question in some other posts... can't seem to locate them now so I'll summarize:

argument passing options are:
1. node/123/a1/a2, then use drupal's arg() function to access arg1 and arg2 [arg(0)=node, arg(1)=123, arg(2)=a1, etc.]
2. alias?x=a1&y=a2, then use php's $_GET['x'] to access a1, etc.
3. write a custom module to handle alias/*

It seems you can't just add the arguments on the end of a url alias like alias/a1/a2 because drupal resolves the aliases before parsing the arguments (so if there no "alias/a1/a2" defined as an alias, you'll just get the 404 error).

danielb’s picture

$alias = drupal_get_path_alias($GET['q']);
$alias_parts = explode('/', $alias);

virtualdrupal’s picture

Thanks for this