在直接网址上点击它显示我想不要做的结果但是当我给它许可它应该可以正常工作。请帮助我,我将非常感谢你。
这是我的模块为我提供该模块的代码:
<?php
// $Id: person.module
/**
* implements hook_menu()
*/
function person_menu(){
$items = array();
$items['person'] = array(
'title' => "Person",
'page callback' => "perso_personal_info", // after visit drupal6/person, person_personal_info() function is called
'access callback' => true, // must return true, otherwise it will not visible as menu item
'type' => MENU_NORMAL_ITEM, // drupal's default menu type
'weight' => '10', // we want to display person link below in our nav menu
);
return $items; // finally, do not forget to return $items array
}
function perso_personal_info(){
$output = 'Name: Gaurav</br>';
$output .= 'City: nanital </br>';
$output .= 'Country: india </br>';
return $output;
}
function person_permission(){
return array(
'administer my module' => array(
'title' => t('Administer my module'),
'description' => t('Perform administration tasks for my module.'),
),
); }
?>
请提供所需的代码;当我为我的模块设置权限时它应该工作正常。
答案 0 :(得分:0)
您需要更新hook_menu中的“访问回调”,其中将检查用户权限,如下所示:
/**
* implements hook_menu()
*/
function person_menu() {
$items = array();
$items['person'] = array(
'title' => "Person",
'page callback' => "demo_custom_personal_info", // after visit drupal6/person, person_personal_info() function is called
//'access callback' => true, // must return true, otherwise it will not visible as menu item
'access callback' => 'person_personal_info_check_access',
'type' => MENU_NORMAL_ITEM, // drupal's default menu type
'weight' => '10', // we want to display person link below in our nav menu
);
return $items; // finally, do not forget to return $items array
}
现在您需要在模块文件中添加以下功能(此功能将检查将从权限页面分配的用户访问权限)
/**
* To check user's permission
*/
function person_personal_info_check_access() {
if (user_access('administer my module')) {
return TRUE;
}
return FALSE;
}