我们如何在Cakephp中使用SoapClient? [英] How to we use the SoapClient in Cakephp...?

查看:91
本文介绍了我们如何在Cakephp中使用SoapClient?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在本地服务器中启用SOAP。
我的代码是:

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);

在单独的php文件上运行代码时,这里执行成功。但是我遇到了这个错误:

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


错误:找不到类'App\Controller\SoapClient'

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

当我尝试运行CakePHP动作的代码形式。

when I try to run the code form CakePHP action.

请建议我如何使用SoapClient

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

推荐答案

您在另一个命名空间中,而 SoapClient 在根名称空间中,因此请使用 \SoapClient

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;

注意:这不是CakePHP特有的问题,而是常见的命名空间问题。

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

这篇关于我们如何在Cakephp中使用SoapClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆