Somebody help me. I've successfully written a couple of drupal modules, so I've got a little bit of experience under my belt. But I am having this really odd "Page Not Found" error pop up when all my code looks right. I just don't know what's going on with it. Maybe I've just been staring at it for too long and can't see what's right in front of me.

I am creating pages for module output and user interaction, which I have done successfully before. I have a menu callback to a function that creates and returns output. One of them works, but the second one does not. I've tried lots of different stuff, and get the same result each time.

Here is my menu hook:

function business_menu($may_cache) 
{
  $items = array();
  
  if ($may_cache)
  {
  	$items[] = array( 
      'path'               => 'directory/business',
      'callback'           => 'directory_page',
      'type'               => MENU_CALLBACK,
      'access'             => user_access('view all businesses'),
    );
	$items[] = array( 
      'path'               => 'business/category',
      'callback'           => 'category_page',
      'type'               => MENU_CALLBACK,
      'access'             => user_access('view all businesses'),
    );
  }
  
  return $items;
}

Here is a skeleton of the function that works and outputs a page (it's the first item):

// main business directory page
function directory_page()
{
	// start the output
	$output = '';
	
	// create output...
	
	return $output;
}

The output created, among other things, are links to category pages -- the second item in my menu hook. No matter what I put in those links, I get the page not found error.

Here is the page function for the category page:

// category page
function category_page()
{
	// declare output
	$output = '';
	
	// for testing
	$output .= "category page<br />";
	
	// output the output
	return $output;
}

I've tried passing variables and not passing variables. Nothing works. I don't get how I can create several pages in one way, then it just stops working. Clearly, I'm doing something wrong, but I'm not seeing it. Maybe I've just been looking at it too long...

Thanks.

Comments

thecalebrogers’s picture

Does anyone know why my callback function wouldn't work? Anyone see what I'm doing wrong?

Thanks,
Caleb
http://www.education-finder.net

thecalebrogers’s picture

OK, so... feel free to laugh at me.

I deactivated then reactivated the module and the page now works. If someone would be so kind to give me some details on the inner workings of drupal on this matter, I would appreciate it. When developing my other modules, I would just keep them activated, and hit refresh to see the effect of my coding changes. Why will that work, but for this new page to show up I have to deactivate and reactivate the module? Is this something to do with the menu cache system (in 5.2, by the way)?

Thanks,
Caleb
http://www.education-finder.net

gclift’s picture

It's because you wrapped (properly I might add) your menu code in the $may_cache section. $may_cache will equal true only when installing the module. You can add an else block and drupal will call that section of your code of more actions.