Drupal 6 无法构建菜单路由器和链接
当我在 Drupal 中启用新菜单(例如 mymodule)时,Drupal 应该能够从 mymodule_menu (hook_menu) 获取菜单项,处理这些菜单项并将菜单项插入到 menu_router 和 menu_links 表中。
然而,我的 Drupal 却无法做到这一点。每次我启用一个模块(我编写的模块或其他人贡献的模块,或核心模块)时,Drupal 似乎没有获取新信息。新启用的模块中定义的菜单项不会被处理并插入到 Drupal 的菜单系统中。这意味着新启用的模块没有机会工作——因为它无法访问。
我确实通过手动将新模块的菜单项信息插入到 menu_router 和 menu_links 表中来修复此问题,然后新菜单开始工作。但如果我每次启用模块时都必须这样做,这将是一场噩梦。
有人遇到过同样的问题吗?如何解决这个问题?
先感谢您。
When I enable a new menu in Drupal (for example, mymodule), Drupal should be able to get the menu items from mymodule_menu (hook_menu), process the items and insert the menu items to menu_router and menu_links table.
However, my Drupal fails to do so. Each time I enable a module (written by me or modules contributed by others, or core modules), Drupal does not seem to get the new information. The menu items defined in the newly enabled module are not processed and inserted to Drupal's menu system. That means the newly enabled module has no chance to work-- because it's inaccessible.
I did fix this by manually insert the menu item information for the new module into the menu_router and menu_links table and the new menu started working. But this is a nightmare if I have to do this each time I enable a module.
Any one has ever had the same problem? How to fix this?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会使用任何 SQL 与菜单表交互,如果编辑错误的记录,可能会发生一些令人讨厌的事情。
您的 hook_menu 代码中一定有错误。可以贴一下吗?
另外,如果您正在开发一个具有菜单条目的模块,我发现在添加/删除链接时调用 mymodule_init() 内部的这两个函数很方便:
这将刷新所有缓存并重建菜单和任何调用 hook_menu 的内容。如果之后没有出现,那么您的代码有错误。我想看看。
I would not use any SQL to interact with the menu tables, something nasty could happen if you edit the wrong record.
You must have an error in your hook_menu code. Can you paste it?
Also, if you are developing a module that has menu entries, I find that its handy to call these two functions inside of mymodule_init() when adding/removing links:
That will flush all cache and rebuild the menu and anything invoking hook_menu. If it doesn't appear after that, then your code has a bug. I'd like to see it.
您没有报告您使用的是哪个 Drupal 版本,但在 Drupal 6 中,如果不是在某些情况下(安装模块时或模块更新时),则不会调用
hook_menu()
的实现被执行,例如)。如果您的模块更改了菜单回调,但没有要执行的更新,您可以添加包含以下代码的更新函数:
从 index.php 检查变量,如果其值为
TRUE
,然后 Drupal 将自动重建菜单。You didn't report which Drupal version are you using, but in Drupal 6, the implementations of
hook_menu()
are not invoked, if not in some occasions (when a module is installed, or when modules updates are executed, in example).If your module changed the menu callbacks, but it has not an update to execute, you can add an update function containing the following code:
The variable is checked from index.php, and if its value is
TRUE
, then Drupal will automatically rebuild the menus.