<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 周銳 閱讀(292) 評論(0)  編輯  收藏 所屬分類: PHP
    主站蜘蛛池模板: 免费看一级毛片在线观看精品视频| 亚洲av成人无码久久精品 | 男人天堂免费视频| 亚洲一级黄色视频| 农村寡妇一级毛片免费看视频| 亚洲AV网站在线观看| 无套内射无矿码免费看黄| 亚洲国产小视频精品久久久三级| 国产av无码专区亚洲av毛片搜| 大胆亚洲人体视频| 国产vA免费精品高清在线观看| 久久精品国产精品亚洲人人| 九九99热免费最新版| 国内精品久久久久久久亚洲 | 99久热只有精品视频免费观看17| 亚洲日本va午夜中文字幕一区| 91久久精品国产免费一区| 亚洲人成网站在线观看播放青青| 免费观看黄网站在线播放| 亚洲精品GV天堂无码男同| 亚洲国产91精品无码专区| 丝袜足液精子免费视频| 亚洲永久永久永久永久永久精品| 亚欧色视频在线观看免费| 亚洲色www永久网站| 亚洲国产成人久久综合区| 免费一级不卡毛片| 亚洲国产成人va在线观看网址| 日韩电影免费在线| 二区久久国产乱子伦免费精品| 亚洲资源在线视频| 日韩免费一区二区三区| 免费无码黄网站在线看| 亚洲国产高清在线精品一区| 国产成人免费a在线视频app| 女人18毛片免费观看| 亚洲国产成人久久综合| 亚洲国产日韩成人综合天堂| 性色午夜视频免费男人的天堂| 亚洲一级毛片中文字幕| 久久影视综合亚洲|