I have a problem with access callback in drupal.
I have a page which can go only those users whose id is in the table .
PHP
function niiar5c_menu()
{
// Blank5c
$items['blank5c/add'] = array(
'title' => 'Бланк 5С',
'page callback' => 'drupal_get_form',
'page arguments' => array('module_blankadd'),
'file' => 'modul.pages.inc',
'access callback' => 'module_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
return $items;
}
function module_access () {
global $user;
$uuid = $user->uid;
$nids = db_select('whoboss', 'n')
->fields('n', array('name'))
->execute()
->fetchCol();
if (in_array($uuid, $nids)){
return TRUE;} else return FALSE;
}
But function 'module_access' doesn't return true or false.
function module_access () {
return TRUE;
}
It's doesn't return TRUE in 'access callback' On page "You are not authorized to access this page."
I can see that you are providing access arguments as array(1). But your access callback function does not contain any arguments.
Either you can define a function argument inside the access callback function. But I don't see if it is relevant in your case. Get rid of access argument from hook_menu and try again, like below
function niiar5c_menu()
{
// Blank5c
$items['blank5c/add'] = array(
'title' => 'Бланк 5С',
'page callback' => 'drupal_get_form',
'page arguments' => array('module_blankadd'),
'file' => 'modul.pages.inc',
'access callback' => 'module_access',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
return $items;
}
Edit: you will need to define the function module_access inside the file modul.pages.inc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.