Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to we use the SoapClient in Cakephp...?

I have enabled SOAP in my local server. My code is:

ini_set('soap.wsdl_cache_enabled', '0'); 
ini_set('soap.wsdl_cache_ttl', '0'); 
$client = new SoapClient('web_url');
$session = $client->login('username', 'pwd');
$result = $client->call($session, 'function_name', '<id>');
print_r($result);

Here it's executed successfully when I run the code on separate php file. But I got this error:

Error: Class 'App\Controller\SoapClient' not found

when I try to run the code form CakePHP action.

Please suggest me how to we use the SoapClient in CakePHP.

like image 707
Mani K Avatar asked May 26 '15 13:05

Mani K


People also ask

What is a SoapClient?

A SOAP client formulates a request for a service. This involves creating a conforming XML document, either explicitly or using Oracle SOAP client API. A SOAP client sends the XML document to a SOAP server. This SOAP request is posted using HTTP or HTTPS to a SOAP Request Handler running as a servlet on a Web server.

What is SoapClient in PHP?

Description ¶ This is a low level API function that is used to make a SOAP call. Usually, in WSDL mode, SOAP functions can be called as methods of the SoapClient object. This method is useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers.


1 Answers

You're in a different namespace, and SoapClient is in the root namespace, so use \SoapClient:

$client = new \SoapClient('web_url');

Alternatively, near the namespace declaration make a use statement:

namespace App\Controller
use SoapClient;

Note: this isn't a CakePHP specific problem, it's a general namespace issue.

like image 159
MrCode Avatar answered Sep 19 '22 22:09

MrCode