I have a controller inside my module as follows.


 * @file
 * Contains \Drupal\module_name\Controller\ControllerName.
namespace Drupal\module_name\Controller;
use Drupal\Core\Controller\ControllerBase;

 * NuSoap is required, and included here.
    include 'nusoap/nusoap.php';
    class ControllerName extends ControllerBase { 

      private static $instance = NULL;
      private $session_result, $myconnection, $namespace;
      private $debug = 0;
      private $servicestatus = false;
      private $logedin = false;   
      private $appliances = array();

      /* process() retries, on error 503, $max_retries times 
       * every $recursion_timeout seconds 
      private $max_retries = 15;
      private $recursion_timeout = 1;
      private $logfile = '';

      public function __construct ($ip, $user, $password) {
        $this->myconnection = new nusoap_client("https://" . $ip ."/sdk/");
        $this->myconnection->timeout = 10;
        $this->myconnection->soap_defencoding = "UTF-8";
        $this->namespace = "urn:vim25";
        $status = $this->_Login($user, $password);
        if (!$status) {
              'Unable to connect to vCenter "@ip", check connection!',
              array('@ip' => $ip)

and i have a folder structure inside module as nusoap/nusoap.php as follows

class nusoap_client extends nusoap_base  {

 var $username = '';                // Username for HTTP authentication
var $password = '';             // Password for HTTP authentication
var $authtype = '';             // Type of HTTP authentication
var $certRequest = array();     // Certificate for HTTP SSL authentication
var $requestHeaders = false;    // SOAP headers in request (text)
var $responseHeaders = '';      // SOAP headers from response (incomplete namespace resolution) (text)
var $responseHeader = NULL;     // SOAP Header from response (parsed)
var $document = '';             // SOAP body response portion (incomplete namespace resolution) (text)
var $endpoint;
var $forceEndpoint = '';
stuff ... 


As you can see it is extending the base class, but whenever I run this using the router I am getting the following error:

Class 'Drupal\module_name\Controller\nusoap_client' not found

Is it because the wrong usage of the include files in Drupal 8? How can I include files in a controller?

As a note there are more dependent files calling the nusoap inside the nusoap folder.

  • This is exactly the same question as you asked earlier - either answer from the other question will fix your problem, once you understand what namespaces are and how to use them. You also have an issue related to the path you're including, but again that's just basic PHP and not related to Drupal – Clive May 10 '16 at 15:37
  • @clive but this is different since we are not making calls to another module but a class inside a folder from that module itself – Crazyrubixfan May 10 '16 at 15:39
  • It makes no difference - trust me, you need to learn how to use namespaces, then this will all make sense. Drupal can't help you with that, and this isn't the right place to teach a general PHP concept. To get you started: nusoap_client isn't in a namespace judging from the error. Put it in an appropriate namespace (Drupal\module_name\Controller would be the least work), or reference it as a global class with a leading backslash, e.g. \nusoap_client, and you'll be well on your way – Clive May 10 '16 at 15:43
  • @Clive is there any restriction that we should use namespaces and convert the entire folder to a module structure and call the class ?? OR can we just include from a folder like php way ?? – Crazyrubixfan May 10 '16 at 15:55
  • 1
    I would rather convert all to a Drupal service, but that is what I would do, not something that needs to be done so. – kiamlaluno May 10 '16 at 18:22

Browse other questions tagged or ask your own question.