I have a custom module where I've separated out certain functions into other files for better readability.
For example:
- ftw.module
- ftw.youtube.inc
- ftw.tmdb.inc
What's the best way to include the two '.inc' files from my '.module' file?
module_load_include()
seems like the obvious choice, but its documentation says:
Do not use this function in a global context since it requires Backdrop to be fully bootstrapped, use require_once BACKDROP_ROOT . '/path/file' instead.
What does 'in a global context' mean?
Does it mean at the top of my module file, outside of any functions? Or something else? Requiring Backdrop to be fully bootstrapped seems like that'd always be the case from within my module, right?
Comments
Yes, it does mean outside your functions. You can use
module_load_include()
within functions but not outside. The YouTube module gives an example:This way is slightly easier than
BACKDROP_ROOT
as it is relative to your main module file.Additionally, "outside" means a file that is located outside a module folder. The second parameter of
module_load_include()
is the name of a module, so, this function assumes that you are loading a file located within that module's folder. But if you wanted to load a file from (for example) an independent library that's not part of a module and is located somewhere in your installation, you need to useinclude_once
orrequire_once
.