Drupal:在 hook_init() 中捕获 userId;
我在自定义模块中有以下代码,并且安装了 firePHP(dfb($userId) 应该在控制台中编写)。 在每个页面加载时,我想捕获并打印当前用户 ID,我认为以下内容应该有效,但事实并非如此 - 谁能告诉我为什么?
function live_update_test_init() {
global $user;
$userId = $user->uid;
dfb($userId);
// Tell drupal that we should watch for new
if (arg(0) == 'frontpage' && !arg(1)) {
live_update_initialize('live-update-test');
}
}
I have the following code in a custom module as well as I have firePHP installed (dfb($userId) is supposed to be written in the console).
At every page pageload I want to catch and print the current users ID and I think the following should work but it isn't - can anyone tell me why?
function live_update_test_init() {
global $user;
$userId = $user->uid;
dfb($userId);
// Tell drupal that we should watch for new
if (arg(0) == 'frontpage' && !arg(1)) {
live_update_initialize('live-update-test');
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
hook_init
不会在缓存页面上运行,这可能就是您所看到的。如果您甚至想在缓存页面上运行代码,您应该使用hook_boot
,但要小心不要做一些昂贵的事情,因为它可能会对性能造成巨大影响。hook_init
wont be run on cached pages, that is probably what you are seeing. If you want to run code even on cached pages you should usehook_boot
, but be careful not to do something expensive, as it can become a huge performance hit.