通过 URI(而不是 GET 方法)将值传递给函数
我正在编写一个 Drupal 6 模块,该模块通过 URI 将用户 ID + 随机生成的字符串发送到函数。我正在使用菜单挂钩:
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),
'type' => MENU_CALLBACK
);
// ...
}
我是 Drupal 的新手,但据我了解(而且我很可能是错误的),这应该将两个值传递给回调函数,出于测试目的,当前看起来像这样:
function invites_pageAuth($auth = NULL, $uid = NULL) {
drupal_set_message("uid: $uid <br /> $auth");
}
我使用的 URL是“invites/auth/RANDOMSTRING/USERID”。这似乎两次获得第一个值; $auth 和 $uid 都包含“RANDOMSTRING”。
我错过了一些非常简单的东西吗?
谢谢。
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_pageAuth',
'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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也可以使用 arg(3) 作为用户对象 ->使用 %user 而不是 %,您将在回调中获得 user 对象
Also you can use arg(3) as user object -> use %user instead % and you will get user object in your callback
我对文档的阅读是
'page_arguments' => array(2)
意思是:“将路径组件编号 2 作为第一个参数传递给页面回调,后跟任何可选参数”。所以你会得到:RANDOMSTRING
、RANDOMSTRING
、USERID
。警告:我不是 Drupal 专家,以上内容可能是错误的。您可以通过提供
invites_pageAuth
另一个参数、更改page_arguments
中的2
等轻松检查它。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 the2
in yourpage_arguments
, etc.