How to include file(s) to .module?

sisyphus - November 21, 2008 - 00:39

i would like to break the .module file into several .inc files. how to include them into .module using drupal built-in function?

thanks a lot.

A couple of examples

styro - November 21, 2008 - 02:04

You can specify an external file for your theme functions or preprocess functions:
http://api.drupal.org/api/function/hook_theme/6

Page handlers can be defined in an external file (eg for admin functionality you only want loaded when needed):
http://drupal.org/node/146172

Other hooks may also have ways of including files...

--
Anton

thank you. but i meant is

sisyphus - November 21, 2008 - 03:05

thank you.

but i meant is there any drupal functions similar to require_once() of php or i can use require_once() direct?

thanks.

You should be able to use it directly without any problem

styro - November 21, 2008 - 03:27

Keep in mind that you might need to use a path relative to index.php rather than your module file. There are Drupal functions to give you the paths for modules and theme so you don't have to hard code the path.

I would recommend taking another look at the methods I listed above though. They are more "Drupal native" and can take advantage of future optimisations (eg D7 will have a comprehensive registry) etc. A require_once() will run on every page load, whereas the Drupal registries are designed to only load files when needed.

--
Anton

You could try the

deeporange1 - November 21, 2008 - 04:30

You could try the include_once() function. That is what we use typically. You can use any php function with Drupal...

Regards, Derek

http://collectivecolors.com

Yeah that would be a good

deeporange1 - December 9, 2008 - 00:37

Yeah that would be a good way too!

Derek

 
 

Drupal is a registered trademark of Dries Buytaert.