Drupal:在 hook_init() 中捕获 userId;

发布于 2024-09-13 03:22:54 字数 390 浏览 4 评论 0原文

我在自定义模块中有以下代码,并且安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

套路撩心 2024-09-20 03:22:54

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 use hook_boot, but be careful not to do something expensive, as it can become a huge performance hit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文