多个 URL 指向 hook_menu 中的同一选项卡

发布于 2024-10-12 08:12:04 字数 1669 浏览 1 评论 0原文

这是我正在使用的基本菜单结构:

function events_menu()
{
    $items = array();

    $items['events'] = array(
        'title' => 'Current Events',
        'access callback' => true,
        'page callback' => 'page_event',
        'type' => MENU_CALLBACK,
    );
      $items['events/current'] = array(
          'access callback' => true,
          'type' => MENU_DEFAULT_LOCAL_TASK,
          'weight' => 1,
      );      
      $items['events/regions'] = array(
          'title' => 'Event By Region',
          'access callback' => true,
          'type' => MENU_LOCAL_TASK,
          'weight' => 2,
      );
      $items['events/range/%/to/%'] = array(
          'title' => 'Current Events by Range',
          'access callback' => true,
          'page callback' => 'page_event_range',
          'page arguments' => array(2, 4),
          'type' => MENU_LOCAL_TASK,
          /* Don't want this to be a tab.
             I want it to activate the default tab */
      );

    return $items;    
}

URL(和默认选项卡)events 显示一些数据。我希望 URL events/range/%/to/% 根据传递的 URL 参数过滤数据。

上面的 hook_menu 可以工作,但我不希望 events/range/%/to/% 成为它自己的选项卡。当您使用过滤后的 URL 时,我希望默认选项卡“当前事件”保持活动状态 - 给人一种错觉,即您正在查看与“事件”相同的页面,只是经过过滤。多个 URL 可以指向同一个选项卡吗?

我想我可以在 events 页面回调中使用 arg() 手动处理 url 参数,但这看起来很hacky。有没有办法使用 hook_menu 来做到这一点?

编辑(更清楚地说明):
通常,URL eventsevents/regions 处有“当前事件”和“按区域划分的事件”两个选项卡。我想要一个位于 events/range/%/to/% 的隐藏(仅回调)网址。但是当您访问它时,我希望这两个选项卡保持可见并且“当前事件”处于活动状态 - 就好像我们从未离开过该页面一样。

Here's a basic menu structure I'm working with:

function events_menu()
{
    $items = array();

    $items['events'] = array(
        'title' => 'Current Events',
        'access callback' => true,
        'page callback' => 'page_event',
        'type' => MENU_CALLBACK,
    );
      $items['events/current'] = array(
          'access callback' => true,
          'type' => MENU_DEFAULT_LOCAL_TASK,
          'weight' => 1,
      );      
      $items['events/regions'] = array(
          'title' => 'Event By Region',
          'access callback' => true,
          'type' => MENU_LOCAL_TASK,
          'weight' => 2,
      );
      $items['events/range/%/to/%'] = array(
          'title' => 'Current Events by Range',
          'access callback' => true,
          'page callback' => 'page_event_range',
          'page arguments' => array(2, 4),
          'type' => MENU_LOCAL_TASK,
          /* Don't want this to be a tab.
             I want it to activate the default tab */
      );

    return $items;    
}

The URL (and default tab) events displays some data. I'd like the URL events/range/%/to/% to filter the data based on the passed URL parameters.

The hook_menu above works, but I don't want events/range/%/to/% to be it's own tab. When you use the filtered URL, I want the default tab, Current Events, to remain active -- to give the illusion that you're looking at the same page as events, only filtered. Can multiple URL's point to the same tab?

I guess I could handle the url parameters manually with arg() in the events page callback, but this seems hacky. Isn't there a way to do this using hook_menu?

Edit (stated more clearly):
Normally there are two tabs Current Events and Event By Region at the URLs events and events/regions. I want a hidden (callback only) url at events/range/%/to/%. But when you visit it, I want the two tabs to remain visible and Current Events active - as if we'd never left that page.

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

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

发布评论

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

评论(3

吃素的狼 2024-10-19 08:12:04

我认为仅通过挂钩菜单不可能完成您想要的事情。您可以使用 menu_set_active_trail使 drupal 看起来就像用户正在查看 /events 页面。

上述方法可能仅适用于 Drupal 7

对于 Drupal 6,您可以更改 $_GET['q']。然而,这可能与某些模块(如 purl 或 globalredirect)发生冲突。这不是一个很好的解决方案,但它确实有效。执行此操作的最佳位置是使用 hook_init 在自定义模块中。

I don't think it's possible to accomplish what you want only with hook menu. What you could do it use menu_set_active_trail to make drupal make it look like the users is looking at the /events page.

The above method might only work for Drupal 7

For Drupal 6 you could alter $_GET['q']. This can, however, conflict with some modules like purl or globalredirect. This is not a pretty solution but it works. The best place to do this would be in the a custom module using hook_init.

ま昔日黯然 2024-10-19 08:12:04

使用 MENU_CALLBACK 而不是 MENU_LOCAL_TASK,选项卡将会消失。然后将当前菜单项设置为“事件”,如下所示(可能仅在 hook_init 中有效,但您也可以在页面回调中尝试:

$item = menu_get_item();
$item['href'] = 'events';
menu_set_item(NULL, $item);

Use MENU_CALLBACK instead of MENU_LOCAL_TASK, and the tab will disappear. Then set the current menu item to 'events' like so (might only work in hook_init, but you can try it in the page callback too:

$item = menu_get_item();
$item['href'] = 'events';
menu_set_item(NULL, $item);
哆啦不做梦 2024-10-19 08:12:04

您是否尝试过“上下文”模块。您可以为活动菜单设置所需的路径模式。观看这个快速视频演示。

Have you tried 'context' Module. You can set path pattern you want for the active menu. Check out this quick video demo.

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