【问题标题】:Drupal 7: How to Create a Menu/Route Item That Doesn't Appear in the Site NavigationDrupal 7:如何创建不在站点导航中出现的菜单/路由项
【发布时间】:2011-03-02 16:54:38
【问题描述】:

如何在 Drupal 中创建不会自动呈现导航链接的新路线/菜单?

我正在尝试在 Drupal 中创建一个未显示在导航菜单中的简单页面回调。

我有一个名为 helloworld 的模块。

.module 文件包含以下内容

function _helloword_page_callback()
{
    return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you
    for following conventions.');
}

function helloworld_menu()
{
    $items['helloworld'] = array(
      'title'               => 'Hello World',
      'page callback'       => '_helloword_page_callback',
      'access arguments'    => array('content'),
      'type'                => MENU_CALLBACK
    );
    return $items;
}

这成功地暴露了网站上的一个 URL

http://example.drupal.com/helloworld

但是,尽管使用了

,但我仍然在左侧 (Bartik) 导航菜单中看到了一个链接
'type'              => MENU_CALLBACK

那么,为什么这不起作用?我是否正确配置了菜单项?一个更可能的问题:我如何误解菜单类型常量/系统的使用?是否有额外的缓存来清除它

drush cc all

不会照顾?我还可以采取哪些其他步骤来调试它?

【问题讨论】:

    标签: drupal drupal-7 drupal-routes


    【解决方案1】:

    一定有其他问题(也许你忘了清除缓存?)因为即使使用 Bartik,它也能按预期工作。在该示例中,导航中仅显示“Hello 2”:

    function helloworld_menu(){
        return array(
            'hello1' => array(
                'title'               => 'Hello 1',
                'page callback'       => 'helloworld_page_callback',
                'access arguments'    => array('content'),
                'type'                => MENU_CALLBACK
            ),
            'hello2' => array(
                'title'               => 'Hello 2',
                'page callback'       => 'helloworld_page_callback',
                'access arguments'    => array('content')
            )
        );
    }
    
    function helloworld_page_callback(){
        return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you for following conventions.');
    }
    

    顺便说一句,您的代码中有一个错字(helloroute_menu 应命名为 helloworld_menu),但我认为这是由于在 StackOverflow 上发布之前代码简化所致。

    【讨论】:

    • 感谢您提供的信息。它绝对是某个地方的缓存。如果将我的路线更改为不同的名称(helloworld 到 helloworld2),则新路线的不同名称没有菜单。只有当我有一个带有默认导航链接的菜单项并且我尝试更改它时它才不起作用。 (即使调用了 drush 的 cc all,这又是另一个问题了)。感谢您的健全性检查!
    • 不客气 :) 顺便说一句,有趣的“quick brown fox”填充文字,我一开始并没有注意到这不是通常的报价:D
    【解决方案2】:

    在菜单管理中查看该菜单链接。如果您在那里对其进行了自定义(例如重量变化),即使您将类型设置为回调,它也可能保留。

    如果是这样的话,你可以在那里删除。

    【讨论】:

    • +1 (一如既往)好信息。不过它看起来像一个缓存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    相关资源
    最近更新 更多