<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
    主站蜘蛛池模板: 99精品视频在线观看免费播放| 日韩久久无码免费毛片软件| 中文字幕无码毛片免费看| 亚洲福利视频一区二区| 久久w5ww成w人免费| 国产精品亚洲片在线| 永久免费av无码入口国语片| 国产AV无码专区亚洲AV漫画| 亚洲一区二区三区免费| 亚洲精品制服丝袜四区| 日本免费在线中文字幕| 亚洲网站在线免费观看| 无码专区永久免费AV网站| 亚洲色大网站WWW永久网站| 日韩免费视频在线观看| 国产大陆亚洲精品国产| 久久亚洲中文字幕精品一区| 国产情侣久久久久aⅴ免费| 亚洲经典在线观看| 免费观看激色视频网站bd| 亚洲自偷自偷在线成人网站传媒 | 亚洲午夜无码毛片av久久京东热| 最近的免费中文字幕视频| 亚洲国产精品精华液| 亚洲精品无码久久毛片| 亚洲第一男人天堂| 国产一级淫片免费播放| 在线免费观看伊人三级电影| 亚洲综合色丁香麻豆| 国产成人3p视频免费观看| 黄床大片免费30分钟国产精品 | 免费大香伊蕉在人线国产| 国产精品福利片免费看| 亚洲精品第一国产综合精品| AA免费观看的1000部电影| 国产亚洲人成在线影院| 亚洲AV无码一区二区乱子伦| 无码一区二区三区免费视频| 深夜a级毛片免费无码| 91在线精品亚洲一区二区| 免费观看国产精品|