How to set the parent of menu items creating using hook_menu()? I need creating a series of menu items dynamically based on values from the database.

Here is a example of my hook_menu() function; in this snippet, I removed the DB queries and just added an array to prove the concept:

function MYMODULE_menu() {
  $years = array(2011, 2010, 2009);

  foreach ($years as $year) {
    $items['events/' . $year] = array(
      'title' =&gt; $year . ' Events Archive',
      'page callback' =&gt; 'page_archive',
      'page arguments' =&gt; array(1),             
      'access callback' =&gt; TRUE,
      'type' =&gt; MENU_NORMAL_ITEM,
      'menu_name' =&gt; 'main-menu',
    );  
  }

  return $items;
}


This works and I get three menu items in the Main Menu titled 2011 Events Archive, 2010 Events Archive and 2009 Events Archive.

The problem I am having is the position of the dynamically created menu items in the Main Menu tree; they appear at the top level, but I want they appear under the parent Events menu item.

Currently, my menu tree looks something similar to the following.


Home
Events
About Us
Contact Us
2011 Events Archive
2010 Events Archive
2009 Events Archive


It should look like the following.


Home
Events

2011 Events Archive
2010 Events Archive
2009 Events Archive

About Us
Contact Us


I know you can move the menu items using the Menu editor UI when logged in, but as these will be automatically created by the system; they need to appear automatically under Events without human intervention.

How can this be done? Is there an easier way to do this?
Since the Events menu item links to a node, for which events is a path alias, what you are trying to achieve should work if you define the menu items using the following code (I use "11" as node ID).

function MYMODULE_menu() {
  $years = array(2011, 2010, 2009);

  foreach ($years as $year) {
    $items['node/11/' . $year] = array(
      'title' =&gt; $year . ' Events Archive',
      'page callback' =&gt; 'page_archive',
      'page arguments' =&gt; array(1),             
      'access callback' =&gt; TRUE,
      'type' =&gt; MENU_NORMAL_ITEM,
      'menu_name' =&gt; 'main-menu',
    );  
  }

  return $items;
}


This is necessary because, if events is a path alias for node/11, Drupal doesn't expand events/2011 to node/11/2011. In the same way, it will not expand events/edit to node/11/edit, even thought the Node module defines nodes/%node/edit as one of its menu items.