How do we use SoapClient in Cakephp ...?

I have enabled SOAP on 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 is executed successfully when I run the code in a separate php file. But I got this error:

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

when I try to start CakePHP action form code.

Please suggest me to use SoapClient in CakePHP.

+6
source share
1 answer

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

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

Also, next to the namespace declaration, create a use statement:

 namespace App\Controller use SoapClient; 

Note. This is not a special CakePHP problem, it is a common namespace problem.

+9
source

Source: https://habr.com/ru/post/987939/


All Articles