Hello,

I have defined a function called mymdoule_add_event in mymodule.pages.inc. It is acting as a page callback function, to serve the below menu path.

  $items['add_event'] = array(
    'title' => 'Add Event',
    'description' => 'Add an event to schedule',
	'page callback' => 'mymodule_add_event',
	'page arguments' => array(1,2),
    'access callback' => TRUE,
    'file' => 'mymodule.pages.inc',
    'type' => MENU_CALLBACK,
  );

No issues with the above code.
However, later on I found that I would also need to call mymodule_add_event from other code in mymodule.module file. Off course I get a "Call to undefined function" error, since the function is in mymodule.pages.inc.

Now, I'm sure there are a few workarounds. However what is the "Drupal" way of doing this? Also, I would appreciate some pointers/guidelines as to where to define my functions in general.

Appreciate your help!
Thanks.

Comments

John Pitcairn’s picture

Use module_load_include() to include your mymodule.pages.inc file before you call the function.

ShErbO’s picture

That worked, simple & easy. Thanks John!