Hi!
I´m new to drupal and I´m currently developing a few modules that are supposed to share some library code that must be included. The problem is, that, when trying to include these library files, it seems as if the include_once statements are ignored. (It doesn´t matter if I write the exact filename ("filename.php") or a wrong one("filenamehbejkfg.php"), and, of course, the include-file´s content cannot be accessed.)
How am I supposed to handle include files in Drupal? Must I name them ".inc" and put them in the includes directory? Which is something I really wouldn´t appreciate...

Thanks
Sören

Comments

soerenP’s picture

The stupid include_once will just do nothing. Even do not return a value???

echo (include "fbConnectTest.info"? 'true':'false');
exit();

Won´t echo anything

echo('false');
exit();

Will echo false, of course...
Please help me, this is driving me crazy!
Cheers
Sören

wla_g’s picture

include_once will work. I've included it into my modules .module file. However, when the file, where this is done hasn't been loaded for some reason, it may well be, that the include hasn't been done so far. Use function_exist to check, if the function you want is there and if not, do an iclude_once. That will work.

Regards
Werner

soerenP’s picture

Sorry, include_once WON´T work. It doesn´t matter if I write include or include_once.
I really don´t get that any more.
It seems as if the file included must exist in the module´s directory. Even if I put it in a subdirectory I get a strange behaviour. if they reside in sites/all/modules/lib for example, they won´t be included...

Thanks
Sören

EDIT: I use "include_once "../lib/FacebookUser.php" " when trying to include the above example.
EDIT2: It seems as if I am not able to include anything outside of my module directory. Which is, of course, a bit unfortunate if I want multiple modules share the same code :(

EDIT3: the sites/all/ directory did it!!! ;) Part of it seemed to be a caching problem :(

wla_g’s picture

It works, but of course you need to specify the correct path as in the following coding

  if( ! function_exists("node_object_prepare")) { 
     include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
  }

This way you can include the file located in another modules directory.

Regards
Werner