How to we use the SoapClient in Cakephp…?

▼魔方 西西 提交于 2019-12-19 06:57:51

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/30460247/how-to-we-use-the-soapclient-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!