1

I've got a module that I've created just for the sole purpose of sharing .inc files between multiple modules. The modules .module file is empty, as it doesn't do anything. But in the modules .info file I have included:

files[] = includes\Permissions.inc
files[] = includes\Roles.inc
files[] = includes\PermissionsInterface.inc
files[] = includes\RolesInterface.inc

And then in a module that is using these files (a different module), I have included:

use Portal\Permissions;
use Portal\Roles;

$permissions = new Permissions\Permissions();
$roles = new Roles\Roles();

I don't have any include or require statements, because I thought that was covered by the files[] declaration in the shared modules .info file.

However, I'm getting a PHP error that it can't find the class Permissions(). Just wondering what I'm doing wrong?

  • Is this running on a Windows machine? Im wondering why you use backslashes in your paths, or if that's even valid for a Windows machine (I've never tried it with Drupal). BTW you can remove the use statements as D7's autoloading is not namespace-aware – Clive Dec 19 '13 at 16:23
1

The files[] = declarations are only for classes you want to reference at runtime. The declaration should be in the module using the classes (not some other module).

If that doesnt work, look at the xautoload module for D7. Or, simply put include 'includes/Permissions.inc'; into the top your custom module file using those classes/functions -- if you use Features, that's what features (for D7) does; adds an include for features.inc.

  • This partially worked. I fixed the problem by creating require_once statements inside the module that was sharing out the files. – Arak Tai'Roth Dec 19 '13 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.