Drupal clears urls on a GET request page
I have a drupal page (content type page) that needs to accept GET values using clean urls.
I put the following code in the body of the page using php code input format.
<?php
$uid = $_GET['uid'];
$user = user_load($uid);
print $user->name;
?>
Now the following link http://www.example.com/mypath/?uid=5 will display username 5. Great.
My question is, can this be accomplished using clean urls so that going to http://www.example.com/mypath/5 has the same result? (Similar to using arguments in views)
a source to share
You can do what you ask in the menu system using hook_menu
in a module, but you cannot create an alias where part of it is the name. The entire alias is a name, so you cannot extract information from it. Using hook_menu
, you can do this:
function my_module_menu() {
$items = array();
$items['path/%user'] = array(
'title' => 'Title',
'page callback' => 'callback',
'page arguments' => array(1),
'access callback' => '...',
'access arguments' => array(...),
);
return $items;
}
Then, in your callback function, you will get the value or argument 1 in the path that matches the uid (it will actually be the loaded custom object from behind %user
).
a source to share
Yes. Use arg () instead of $ _GET
Be aware that arg () uses $ _GET ['q'] by default and therefore effectively translates the alias before returning the result. Thus, the parameter you are trying to get might be in a different position.
For example, the path myalias / 5 might translate to taxonomy / term / 5. In this case, arg (2) is 5.
For more information on the Drupal arg () function see http://api.drupal.org/api/function/arg/6
a source to share