drupal模块重定向目标问题
我正在研究另一个模块的想法。该模块只是应该将用户自动重定向到指定节点,如以下示例代码所示:
function test_module_init(){
drupal_goto('node/100');
}
该代码只是一个示例。但是,真正的问题是代码一直执行,直到浏览器返回“太多重定向”错误消息。
我明白为什么会发生这种情况。我需要帮助的是放置 drupal_goto 代码的最佳钩子,以便它执行一次,而不是当前在 hook_init 中执行的多次。
I am working on yet another module idea. This module is simply supposed to redirect a user automatically to a specified node like in the following example code:
function test_module_init(){
drupal_goto('node/100');
}
The code is a mere example. But, the very really problem is the code keeps executing until the browser returns a "too many redirects" error message.
I understand why this is happening. What I need help with is the best hook to place my drupal_goto code so it executes once instead of the multiple times it currently does in hook_init.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能做这样的事情吗:
Can't you just do something like this:
您编写的 init 钩子会在每次页面加载时触发,包括当您位于 node/100 时。这就是您获得重定向的原因。所以页面正在重定向到其自身。如果您尚未位于 node/100 上,您实际上只需要重定向。如果需要,您可以在 $_GET['q'] 中找到此信息。
您不需要不同的钩子,只需确保如果您已经在目标页面上,就不会调用 drupal_goto 。
The init hook you wrote fires on every page load including when you are on node/100. That's why you're getting a redirect. So the page is redirecting to itself. You really only need to redirect if you're not already on node/100. You can find this info in $_GET['q'] if you need to.
You don't need a different hook you just need to make sure that you don't call the drupal_goto if you're already on the destination page.