1

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:

-my_project
--src
---Plugin
----Action
-----MyAction.php
---libs
----mylibs
-----src
------ClassWhichINeed.php

--my_project.info.yml

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
-1

suggestion:

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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