6

如何在 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

但是,尽管使用了

'type'              => MENU_CALLBACK

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

drush cc all

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

4

2 回答 2

6

肯定有其他问题(也许您忘记清除缓存?)因为即使使用 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 上发布之前代码简化所致。

于 2011-03-02T17:03:59.823 回答
4

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

如果是这种情况,您可以在那里删除。

于 2011-03-02T17:19:55.937 回答