繁体   English   中英

Drupal 7-通过代码创建多个自定义菜单项的最合适方法

[英]Drupal 7 - Most Appropriate Way to Create Multiple Custom Menu Items Via Code

我目前有一个使用以下代码创建的自定义菜单项,它的效果很好:

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

    $items['myModule'] = array(
        'title' => 'Business Owner Dashboard',
        'page callback' => '_custom_page',
        'access arguments' => array('use_business_dashboard'),
        'type' => MENU_NORMAL_ITEM,
    );

    return $items;
}

我要为多个角色创建多个菜单项,而不仅仅是一个。 我假设我可以某种方式使用开关盒,但是我不确定如何使用该开关盒,并且找不到有关该主题的任何文档。

为了澄清起见,我想使用相同的myModule_menu()函数来设置“企业主仪表板”以及另一个菜单项“ Referrals”,并使用不同的“页面回调”,“访问参数”等。这个话题将不胜感激!

添加更多菜单项非常简单-只需在$items数组中定义另一个元素:

function myModule_menu() {
    $items['admin/business'] = array(
        'title' => 'Business',
        'description' => 'Business.',
        'page callback' => '_administer_business',
        'access arguments' => array('administer business'),
        'file' => 'business.admin.inc', //if the page callback function is in another file
    );
    if (referrals_allowed) {
        $items['admin/referrals'] = array(
            'title' => 'Referals',
            'description' => 'Referrals.',
            'page callback' => '_administer_referrals',
            'access arguments' => array('administer referrals'),
            'file' => 'referrals.admin.inc', //if the page callback function is in another file
        );
    }

    return $items;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM