Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am a newbie to Drupal, and have used CakePHP and Codeigniter frameworks earlier. In Codeigniter, a URL such as /users/show/1 would be interpreted as it invoking the show() method of the Users class, passing 1 as user ID. Can we interpret a Drupal URL in this way?

If we have a URL similar to /admin/xyz?u=1, where in the admin module can I find this?

Also, I know Drupal uses a good bit of path alias. Would that affect this in a big way?

share|improve this question

3 Answers

If your looking at code, all the hook_menu function calls is how the non alias paths get created. Things like users and nodes use a % in the path creation; this turns into the argument for the page callback function. Read more about this here: Wildcard Loader Arguments.
node_menu()

function node_menu() {
...
  $items['node/%node'] = array(
    'title callback' => 'node_page_title', 
    'title arguments' => array(1), 
    'page callback' => 'node_page_view', 
    'page arguments' => array(1), 
    'access callback' => 'node_access', 
    'access arguments' => array('view', 1), 
    'type' => MENU_CALLBACK,
  );
...
}

user_menu()

function user_menu() {
...
  $items['user/%user_uid_optional'] = array(
    'title' => 'My account', 
    'title callback' => 'user_page_title', 
    'title arguments' => array(1), 
    'page callback' => 'user_view', 
    'page arguments' => array(1), 
    'access callback' => 'user_view_access', 
    'access arguments' => array(1), 
    'parent' => '', 
    'file' => 'user.pages.inc',
  );
...
}

The function that handles this menu information is menu_execute_active_handler().
Aliases happen as the 2nd to last part of the bootstrap in the drupal_init_path function. It converts /about-us into node/4 for internal use.

For more in depth information check out this link: Drupal menu system (Drupal 6.x)

share|improve this answer

The answer given by mikeytown2 is correct, but it doesn't report what happens before the implementation of hook_menu() made from the modules are invoked.

If you have clear paths enabled in your Drupal site, a URL like example.com/node/1 is converted from the .htaccess file used by Drupal in example.com/index.php?q=node/1. The content of the index.php file is the following one (for Drupal 7):

define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();

It is menu_get_active_handler() that, through menu_get_item(), finds which callback outputs the content of the required page (in the example, node/1). Drupal allows the modules to define the paths they are able to handle through wildcards, such as in node/%node, or with plain paths, such as admin/config/search/path; the difference is that in the first case the module is able to handle paths such as node/1, node/2, node/444 while in the second case the module report the exact path it is able to handle.
The modules implement hook_menu() that allows them to define which page callback they assign to the path; that callback is the function that outputs the content that is shown when that path is required.

share|improve this answer

Drupal relies on several basic URLs such node/# or user/#. No further direction is taken from the base URL name. Path alias's can be used to hide the base URL, but its structure is up to the user. Certain modules such as views or panels will read the urls and are capable of using the alias information to perform contextual filtering or create custom displays.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.