<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0

    Access Control

    Usually menu access is controlled by defining permissions inside the

    module using hook_perm() and testing those permissions using user_access().

    function mymenu_perm() {

           return array('receive greeting', 'receive goodbye');

    }

    function mymenu_menu($may_cache) {

           $items = array();

           if ($may_cache) {

                  // Define a static menu item.

                  $items[] = array(

                         'title' => t('Greeting'),

                         'path' => 'mymenu',

                         'weight' => -10,

                         'callback' => 'mymenu_hello',

                         'callback arguments' => array(t('Hi!'), t('Ho!')),

                         'access' => user_access('receive greeting')

                  );

                  $items[] = array(

                         'title' => t('Farewell'),

                         'path' => 'mymenu/goodbye',

                         'callback' => 'mymenu_goodbye',

                         'access' => user_access('receive goodbye')

                  );

           }

           return $items;

    }

    Assigning Callbacks Without Adding a Link to the Menu

    Often you may want to map a URL to a function without creating a visible menu item. You

    can do this by assigning the MENU_CALLBACK type to your menu item, as in this example from

    node.module:

    $items[] = array(

           'path' => 'rss.xml',

           'title' => t('RSS feed'),

           'callback' => 'node_feed',

           'access' => user_access('access content'),

           'type' => MENU_CALLBACK

    );

    Displaying Menu Items As Tabs

    In Drupal’s admittedly obscure menu lingo, a callback that is displayed as a tab is known as a

    local task and has the type MENU_LOCAL_TASK or MENU_DEFAULT_LOCAL_TASK. The title of a local

    task should be a short verb, such as “add” or “list.” Local tasks usually act on some kind of

    object, such as a node, user, or workflow.

    Local tasks must have a parent item in order for the tabs to be rendered. A common practice

    is to assign a callback to a root path like milkshake, and then assign local tasks to paths that

    extend that path, like milkshake/prepare, milkshake/drink, and so forth. Drupal has built-in

    support for two levels of tabbed local tasks.

    function milkshake_menu($may_cache) {

           $items = array();

           if ($may_cache) {

                  $items[] = array(

                         'path' => 'milkshake',

                         'title' => t('Milkshake flavors'),

                         'callback' => 'milkshake_overview',

                         'access' => TRUE

                  );

                  $items[] = array(

                         'path' => 'milkshake/list',

                         'title' => t('List flavors'),

                         'type' => MENU_DEFAULT_LOCAL_TASK, //默認選上此menu

                         'access' => TRUE,

                         'weight' => 0

                  );

                  $items[] = array(

                         'path' => 'milkshake/add',

                         'title' => t('Add flavors'),

                         'callback' => 'milkshake_add',

                         'type' => MENU_LOCAL_TASK,

                         'access' => TRUE,

                         'weight' => 1

                  );

                  $items[] = array(

                         'path' => 'milkshake/list/fruity',

                         'title' => t('Fruity flavors'),

                         'callback' => 'milkshake_list',

                         'type' => MENU_LOCAL_TASK,

                         'access' => TRUE,

                  );

                  $items[] = array(

                         'path' => 'milkshake/list/candy',

                         'title' => t('Candy flavors'),

                         'callback' => 'milkshake_list',

                         'type' => MENU_LOCAL_TASK,

                         'access' => TRUE,

                  );

           }

           return $items;

    }

    function milkshake_overview() {

           $output = t('The following flavors are available...');

           // ... more code here

           return $output;

    }

    function milkshake_add() {

           return t('milkshake add');

    }

    If you want the menu item to show up in the administrative menu block, you have to make

    the type a MENU_NORMAL_ITEM instead of a MENU_LOCAL_TASK. And if you want it to show up in both

    places, use the following:

    'type' => MENU_NORMAL_ITEM | MENU_LOCAL_TASK

    Programmatically Modifying Existing Menus

    1Wrapping Calls to Menu Items

    /**

    * Implementation of hook_menu().

    */

    function mymodule_menu($may_cache) {

           $items = array();

           if (!$may_cache && module_exist('devel')) { // Make sure devel.module is enabled.

                  $items[] = array(

                         'path' => 'devel/cache/clear', // Same path that devel.module uses.

                         'title' => t('Wrap cache clear'),

                         'callback' => 'mymodule_clear_cache',

                         'type' => MENU_CALLBACK,

                         'access' => user_access('access devel information') // Same as devel.module.

                  );

           }

    }

    function mymodule_clear_cache() {

           drupal_set_message('We got called first!');

           // Wrap the devel function normally called.

           devel_cache_clear();

    }

    2Deleting Existing Menus

    $items[] = array(

           'path' => 'node/add',

           'title' => t('This should not show up'),

           'callback' => 'drupal_not_found',

           'type' => MENU_CALLBACK

    );

    Adding to Existing Menus

    $items[] = array(

           'path' => 'admin/user/user/eradicate',

           'title' => t('Eradicate all users'),

           'callback' => 'mymodule_eradicate_users',

           'type' => MENU_LOCAL_TASK,

           'access' => TRUE

    );

    posted on 2007-12-03 10:01 周銳 閱讀(294) 評論(0)  編輯  收藏 所屬分類: PHP
    主站蜘蛛池模板: 在线亚洲精品自拍| 人人狠狠综合久久亚洲高清| 亚洲嫩模在线观看| 99精品热线在线观看免费视频| 国产AV无码专区亚洲AV男同| 一个人免费视频在线观看www| 国产亚洲av人片在线观看| 中文字幕在线观看免费| 亚洲精品无码高潮喷水在线| 中文字幕久精品免费视频| 亚洲国产精品久久久久久| 最近中文字幕高清免费中文字幕mv | 无码一区二区三区AV免费| 亚洲国产日韩综合久久精品| 日韩在线免费看网站| 激情吃奶吻胸免费视频xxxx| 亚洲色偷拍区另类无码专区| 中出五十路免费视频| 亚洲精品电影天堂网| 成人A级毛片免费观看AV网站| 亚洲AV无码一区二区一二区 | 国产亚洲一区二区三区在线不卡 | 学生妹亚洲一区二区| 国产最新凸凹视频免费| 中文日本免费高清| 99亚洲精品高清一二区| 丁香花在线观看免费观看| 黄色一级毛片免费| 精品国产亚洲一区二区三区 | 免费永久看黄在线观看app| 美女被免费网站91色| 久久亚洲sm情趣捆绑调教| 午夜老司机免费视频| 国产一级a毛一级a看免费人娇| 久久精品国产亚洲AV无码娇色 | 成人免费视频观看无遮挡| 美女被艹免费视频| 久久久久亚洲av无码专区喷水| 无码一区二区三区免费视频| 一级毛片a女人刺激视频免费| 亚洲国产综合专区在线电影|