views:

82

answers:

2

Hi,

I am creating a small reservation system. you can create nodes of a type that can be reservated, like a projector. I have a calendar view with normal displays. I addes an argument for the node reference, but I have problems defining the page callback. Can someone help me out?

Now I want to create menu items for the different nodes

function your_module_menu() {
$nodeid //semantic, node is loaded right
    $items['reservate/nodeid/$year-w$week'] = array( // semantic, url is built right
        'title' => t('Your Module Name'),
        'description' => t('Menu's description.'),
        'page callback' => 'page_callback_funtion',
        'page arguments' => array('page callback arguments'),
        'access callback' => 'your_module_access',           // the function that validates access based on the user's role(s).
        'access arguments' => array(array(role1', 'role2')), // list of roles authorized - note nested array.
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}

@edit

ok, maybe I didn't explain well :). I have a content type: unit, which can be reserved. for each unit I create, I want to generate a menu item (I can do a menu rebuild on node save or update). the menu should be linked to a view, with the node id (unit) as an argument in the url.

A: 

I'm not sure what exactly you are trying to do, but if your goal is to create a menu item, and not a new page that you define in your custom module, you should use the menu system in Drupal. You can create menu items pointing to any url that exists on your site.
For nodes this is especially easy, since you can do this directly in the node edit/create form.

Drupal caches the menues, so you can't create menu items with dynamic parts in them, like the users id etc. If you want to do something like that, you should create a common callback that either redirects the user to the dynamic url or display content based on the user.

Update

Instead of having to rebuild the menu system each time a node is created or deleted, which won't be very scalable, you could instead just create the new menu item, with hook_nodeapi, and delete it when it's deleted.

googletorp
ok, maybe I didn't explain well :). I have a content type: unit, which can be reserved. for each unit I create, I want to generate a menu item (I can do a menu rebuild on node save or update). the menu should be linked to a view, with the node id (unit) as an argument in the url.
Nealv
A: 

I found a very simple way to do it, I just created a view-block which creates the links with some filters.

simple and exactly what I needed, can't seem to understand why I didn't think of that sooner

Nealv