开发者

Passing values to functions through URI (instead of the GET method)

I'm writing a Drupal 6 module that sends a user ID + a randomly generated string to a function through the URI. I'm using the menu hook:

function invites_menu() {    
  // ...    
  $items['invites/auth'] = array(
    'title' => 'Are you human?',
    'page callback' => 'invites_开发者_如何学JAVApageAuth',
    'access arguments' => array('access invites content'),
    'page arguments' => array(2),
    'type' => MENU_CALLBACK
  );
  // ...
}

I am new to Drupal, but as I understand it (and I could well be mistaken) this should pass two values to the callback function, which for testing purposes currently looks like this:

function invites_pageAuth($auth = NULL, $uid = NULL) {
  drupal_set_message("uid: $uid <br /> $auth");
}

The URL I use is 'invites/auth/RANDOMSTRING/USERID'. This seems to get the first value twice; both $auth and $uid contain 'RANDOMSTRING'.

Am I missing something really simple?

Thank you.


function invites_menu()
{    
...    
    $items['invites/auth/%/%'] = array(
            'title' => 'Are you human?',
            'page callback' => 'invites_pageAuth',
            'access arguments' => array('access invites content'),
            'page arguments' => array(2, 3),
            'type' => MENU_CALLBACK
          );
    ...
}

Also you can use arg(3) as user object -> use %user instead % and you will get user object in your callback

$items['invites/auth/%/%user']


My reading of the docs is that 'page_arguments' => array(2) means: "pass path component number 2 as the first argument to the page callback, followed by any optional arguments". So you'd get: RANDOMSTRING, RANDOMSTRING, USERID.

Warning: I am not a Drupal expert and the above may be wrong. You can check it easily enough by giving invites_pageAuth another argument, changing the 2 in your page_arguments, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜