M4xell
M4xell

Reputation: 321

Symfony 2 SOAP CLIENT

Please tell me why i must put "\" before \SoapClient. When i delete "\", then i have a error.

public function indexAction($name)
{

    try {
            $client = new \SoapClient('some WSDL', array('trace' => 1));
            $a = array('Login'=>'1', 'Password'=>'1', 'LetterNo'=>'1');
            $response = $client->__soapCall('GetTracking', array($a));
            ladybug_dump($response->GetTrackingResult->Status);
        } catch (\SoapFault $e) {
            var_dump($e->getMessage(), $client->__getLastResponse()); die();
    }
    return array('response' => $response);
}

Thanks for help

Upvotes: 3

Views: 10876

Answers (1)

Anthony Sterling
Anthony Sterling

Reputation: 2441

...because your controller is in a namespace, so your call to instantiate SoapClient without the root slash tries to load that object from the current namespace.

App\Controller\SoapClient instead of SoapClient.

You can use a use statement at the top of your controller to bring it into scope. use SoapClient; and you'll be good to go.

Upvotes: 23

Related Questions