I am using the 3d party php library, and I do not know how to connect. The file structure of my project looks like following:



So I need to connect ClassWhichINeed.php to MyAction.php. In ClassWhichINeed.php I specified namespace as Drupal\my_project\mylibs;

And in MyAction.php i use Drupal\my_project\mylibs;

But when I create $object = new ClassWhichINeed;

I get an error "Undefiened class"

  • Use Composer to pull in external dependencies to the project. The autoloader will know how to find them when you add them with use ... statements. – Kevin Nov 14 '18 at 15:08


in MyAction.php add:

require_once DRUPAL_ROOT . '/modules/my_project/src/libs/mylibs/src/ClassWhichINeed.php';
  • This is not necessary to be doing this in Drupal 8. – Kevin Nov 14 '18 at 15: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.