Hello,

I am moving a module that was created for D5 over to D6. I am getting the following error that I believe has to do with permissions based on some searched I have done:

Invalid argument supplied for foreach() in /home/samp2633/public_html/sandbox/includes/menu.inc on line 258

Here is my code:

  function awardcalc_menu() {
    $items = array();

      $items['admin/awardcalc'] = array( 
	  'title' => t('Award Calculator'), 
	  'description' => t('Adjust Award Calculator options.'), 
	  'position' => 'right', 
	  'weight' => -5, 
	  'page callback' => 'system_admin_menu_block_page', 
	  'access arguments' => user_access('administer access control') 
	  ); 
	
  	  $items['admin/awardcalc/settings'] = array(
	  'title' => t('AwardCalc settings'),
	  'description' => t('Change the AwardCalc Variables.'),
	  'page callback' => 'drupal_get_form',
	  'page arguments' => array('awardcalc_admin_settings'),
	  'access arguments' => user_access('administer access control')
	  );
	
	  $items['popup/financial_aid_calculator'] = array(
	  'title' => t('Financial Aid Calculator'),
	  'page callback' => 'drupal_get_form',
	  'page arguments' => array('awardcalc_popup'),
	  'type' => MENU_CALLBACK,
	  'access arguments' => user_access('access content'),
	  );

    return $items;
  }

and here is the function found on line 258:

function menu_unserialize($data, $map) {
  if ($data = unserialize($data)) {
    foreach ($data as $k => $v) {
      if (is_int($v)) {
        $data[$k] = isset($map[$v]) ? $map[$v] : '';
      }
    }
    return $data;
  }
  else {
    return array();
  }
}

Comments

saepl’s picture

I didn't mean to say the problem was related to permissions but to the menu system...oops! Any ideas as to what you think it wrong would be greatly appreciated.

jaypan’s picture

This:

'access arguments' => user_access('access content'),

should be this:

'access arguments' => array('access content'),

Contact me to contract me for D7 -> D10/11 migrations.

saepl’s picture

that worked like a charm! my foreach() errors are gone...now to fix the next one that popped up!

pillarsdotnet’s picture

$dev = new mysqli('localhost', 'user', 'pass', 'database');
$res = $dev->query('
SELECT path, access_arguments, page_arguments, title_arguments FROM menu_router
');
while ($row = $res->fetch_assoc()) {
  foreach (array('access_arguments', 'page_arguments', 'title_arguments') as $field) {
    $path = $row['path'];
    $raw = $row[$field];
    $data = @unserialize($raw);
    if ($data && !is_array($data)) {
      $string = var_export($data, TRUE);
      print "$path $field unserialize('$raw') === $string\n";
    }
  }
}

Good. — Fast. — Cheap.
(Pick any two.)