0

My module creates pages. These pages have dynamic addresses, such as:

How do I assign a page callback to these pages? I get the "page not found error" on these pages.

I am using Drupal 7.

1

I don't understand what you mean by "my module creates pages". It sounds as if you meant to say "URLs" instead of "pages".

Anyway, if you want to link a callback to a URL, you need to implement hook_menu() in a custom module. See the menu_example module and its hook_menu implementation menu_example_menu for an example.

0

You should implement hook_menu_alter to tell Drupal about your dynamically generated paths

  • That is not exact: You can use hook_menu() for menu paths that contains wildcards (see "node/%node" for example), and which match more than one path ("node/%node" matches "node/1," "node/1200," "node/344534545"). – kiamlaluno Nov 6 '11 at 13:49
  • Agree. Yet, I think, hook_menu_alter will be more flexible. – Valery Lourie Nov 7 '11 at 9:41
  • It is not more flexible, and it is not thought for dynamic menus. Its only purpose is to alter what defined with hook_menu() from other modules, which is similar to the purpose of other alter hooks, such as hook_element_info_alter(), hook_form_alter(), or hook_system_info_alter(). – kiamlaluno Nov 7 '11 at 10:23
  • Isn't altering of other modules' menu items a definition of 'dynamic'? :) What if module wants to generate free-form paths, like 'pagepath1', 'anotherpath/someother', 'completely/free/path'? You cannot define paths like these in hook_menu. That's what I meant by hook_menu_alter being more flexible. – Valery Lourie Nov 8 '11 at 14:28
  • The point is that: You use hook_menu_alter() to alter what defined in other modules, not to define you module's menus, for which you use hook_menu(). – kiamlaluno Nov 8 '11 at 14:32

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.