Create object in extbase extension from a PHP stan

2019-08-04 00:49发布

问题:

I am developìng an Extbase extension. Its structure is:

Controller -> MyNameController.php Domain/Model -> MyName.php

In MyNameController.php or MyName.php I want to perform a SOAP request like this one:

(Example in controller)

     $WebService="http://webservice_direction/webservice.asmx?wsdl";

     $username = "username";
     $password = "password";

    $parametros = array();
    $parametros['username'] = $username;
    $parametros['password'] = $password;

    $WS = new SoapClient($WebService, $parametros);

    $result = $WS->myFunction($parametros);

The error:

PHP Fatal error:  Class 'NAMESPACE\MyName\Controller\SoapClient' not found in /DirectoryPlugin/Classes/Controller/MyNameController.php on line X

I know how to include an external class in an Extbase extension, but i dont know how to include one like SOAP or EXCEPTION. How can I create a new object of these classes in the Extbase controller?

回答1:

There's a small bug in your code I think (assuming it's defined in a name space) you should have:

$WS = new \SoapClient($WebService, $parametros);

The leading \ tells php to load SoapClient from the global namespace rather than looking in yours (NAMESPACE\MyName\Controller).