简体   繁体   中英

Access callback. function does not return false and true value

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

  1. Remove 'type' => MENU_LOCAL_TASK. It's for tabs.
  2. Check if parent menu item is accessable 'blank5c'.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM