hook_menu() - 意外行为(较长路径问题)

发布于 2024-09-13 15:48:38 字数 971 浏览 10 评论 0原文

我正在通过 hook_menu (Drupal 6) 初始化多个项目。

...
$items['webtv/block/%/playlist/edit/%'] = array(
  ...
  'page arguments' => array('webtv_playlist_form', 2, 5),
  ...
); 

$items['webtv/block/%/playlist/edit/%/filter/new'] = array(
  ...
  'page arguments' => array('webtv_playlist_param_form', 2, 5),
  ...
);

$items['webtv/block/%/playlist/edit/%/filter/%'] = array(
  ...
  'page arguments' => array('webtv_playlist_param_form', 2, 5, 7),
  ...
);

return $items;

第一个条目是父条目,工作正常。以下两个是子条目。最后两个菜单条目仍然无效并重定向到父页面视图。我通过从路径定义中删除第一个通配符“%/”标记来修复它。

意思是:

$items['webtv/block/%/playlist/edit/%/filter/%']

to

$items['webtv/block/playlist/edit/%/filter/%']

$items['webtv/block/%/playlist/edit/%/filter/new']

to

$items['webtv/block/playlist/edit/%/filter/new']

请帮助我通过添加通配符来解决我做错了什么?超过两张外卡无效吗?

I am initializing a number of items via hook_menu (Drupal 6)

...
$items['webtv/block/%/playlist/edit/%'] = array(
  ...
  'page arguments' => array('webtv_playlist_form', 2, 5),
  ...
); 

$items['webtv/block/%/playlist/edit/%/filter/new'] = array(
  ...
  'page arguments' => array('webtv_playlist_param_form', 2, 5),
  ...
);

$items['webtv/block/%/playlist/edit/%/filter/%'] = array(
  ...
  'page arguments' => array('webtv_playlist_param_form', 2, 5, 7),
  ...
);

return $items;

First entry is a parent entry and works fine. The following two are child entries. These last two menu entries remain invalid and redirects to parent page view. I fixed it with a small modification by eliminating first wild card '%/' mark from the path definitions.

Means:

$items['webtv/block/%/playlist/edit/%/filter/%']

to

$items['webtv/block/playlist/edit/%/filter/%']

and

$items['webtv/block/%/playlist/edit/%/filter/new']

to

$items['webtv/block/playlist/edit/%/filter/new']

Please help me out what I am doing wrong by adding a wild card? Is more than two wild card are invalid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

岁月如刀 2024-09-20 15:48:38

文档中没有充分提及,但可用于 Drupal 菜单回调的路径元素数量有限制 - 请参阅 MENU_MAX_PARTS 常量

对于 Drupal 6,此限制为 7,您的第二条和第三条路径超出了该限制。您的两个修复都将元素计数减少到七个,这就是它们起作用的原因。

It is not mentioned sufficiently in the documentation, but there is a limit on the number of path elements you can use for a Drupal menu callback - see the MENU_MAX_PARTS constant.

For Drupal 6, this limit is seven, which your second and third path exceeded. Both of your fixes bring the element count down to seven, which is why those work.

情泪▽动烟 2024-09-20 15:48:38

正如我提到的,我已经解决了这个问题,没有排除第一个通配符。但我找不到任何逻辑上的理由。

$items['webtv/block/%/playlist/edit/%/filter/%']

$items['webtv/block/%/playlist/edit/%/%']

$items['webtv/block/%/playlist/edit/%/filter/new']

$items['webtv/block/%/playlist/edit/%/new']

I have fixed the issue without excepting first wild card as I mentioned it. But I could not found any logical reason.

$items['webtv/block/%/playlist/edit/%/filter/%']

to

$items['webtv/block/%/playlist/edit/%/%']

and

$items['webtv/block/%/playlist/edit/%/filter/new']

to

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