By sisyphus on
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.
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.
Comments
A couple of examples
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
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
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
yes, use php built-in require_once and dirname(__FILE__)
if you want to include a php file inside your .module file, just use the built-in php function require_once and the built-in php function dirname( __FILE__)
the dirname() funciton gets the file path to the argument passed to it, in this case "__FILE__" which represents the current file where the code is.
don't hard code the path to the include files because it will change on a different server depending on the installation of drupal
by the way, this has worked for me...
you can start the include file with the < ? php tag and you can end it with the closing ? > tag, even though most module instructions say to leave the closing tag off your .module file because drupal will handle the closing of the tag, i just thought you might like to know my experience with this test.
You could try the
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
module_load_include
Hi, I think you're looking for http://api.drupal.org/api/function/module_load_include/6
http://www.davyvandenbremt.be
http://www.drupalcoder.com
Yeah that would be a good
Yeah that would be a good way too!
Derek