This is my hook_menu:

$items['events/%event'] = array(
  'title' => 'Event',
  'title callback' => 'entity_label',
  'title arguments' => array('event', 1),
  'page callback' => 'events_view',
  'page arguments' => array(1),
  'access callback' => 'entity_access',
  'access arguments' => array('view', 'event', 1),
  'file' => 'events.pages.inc',

return $items;

But when I navigate to events/2 there's a 404 error waiting! Here's the page:

Page not found!

As you can see, my Event has been successfully created (it exists in database and its id is definitely 2) but the requested page could not be found and Shortcuts menu and Navigation block has disappeared.
What possibly could I mistaken?
Feel free to ask for more information.

I'm using Drupal 7.12

  • 1
    Why are you trying to access the path shamsi/events/2? Why would that work? – Letharion Feb 21 '12 at 11:36
  • I didn't understand your question! This is the address: localhost/shamsi/events/2 and the corresponding uri in hook_menu would be: events/%event. Right? – Pedram Behroozi Feb 21 '12 at 11:41
  • 1
    @Letharion The site's probably installed in a sub-folder of the web root – Clive Feb 21 '12 at 11:43

If you're getting a 404 it's due to one of the following:

  • You haven't cleared Drupal's cache since you implemented the menu item, OR
  • Your event_load() function is returning FALSE/NULL for the provided ID, OR
  • The function event_load() doesn't actually exist

Judging from the rest of your function/file names (events_view, events.pages.inc) your module is called events so your router load function will probably be called events_load() (note the additional s).

If that's true then you need to change your menu item to match that:

$items['events/%events'] = array(
  // ...

And clear Drupal's cache to pick up the change.

  • Good sight. I didn't notice that s. Thanks. Problem solved immediately :) – Pedram Behroozi Feb 21 '12 at 11:53
  • @PedramBehroozi No problem, I make so many spelling mistakes myself writing code it's always the first place I look! – Clive Feb 21 '12 at 11:54
  • 2
    This is correct: The placeholder name is used as name for the function to load the object, to which is added "_load"; if the placeholder is "%event_node," for example, then Drupal will look for the event_node_load(). If that function doesn't exist, then all users will get a 404 error. – kiamlaluno Feb 21 '12 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.