我收到此错误:
致命错误:在第188行的D:\ xampp \ htdocs \ fsc \ app \ Model \ Datasource \ soapclient \ SforceBaseClient.php中的非对象上调用成员函数__setSoapHeaders()。
我正在使用cakephp框架。当我尝试使用create()方法在salesforce帐户列表中添加帐户数据时。这个__setSoapHeaders()在setHeader()函数中,它给出了这个错误。这个错误是什么解决方案?
在sforceBaseclient.php中,有一个名为setHeader()的函数:
private function setHeaders($call=NULL) {
**$this->sforce->__setSoapHeaders(null); [it gives above error.]**
.
.
}
我希望在用户注册或在我们网站上进行任何交易时在salesforce帐户中添加帐户详细信息。所以我将以下代码放在我的帐户模型中仅供测试,可能是它创建了任何问题:
$mySforceConnection = new SforceEnterpriseClient();
$fieldsToUpdate = array(
'AccountNumber' => 123456,
'BillingCity' => 'Testcity',
'BillingCountry' => 'Testcountry',
'BirthDate' => '27-04-1992'
);
$sObject = new stdClass();
$sObject->fields = $fieldsToUpdate;
$sObject->type = 'Account';
try {
$CreateResponse = $mySforceConnection->create(array ($sObject),'Account');
} catch (Exception $e) {
echo "<BR>Error Creating the Case! ";
echo $e->faultstring;
exit;
}
//To Make sure the case was created successfully.
if ($CreateResponse->success != 1) {
echo "<BR>Error Creating the Account. ";
print_r($CreateResponse->errors->message);
exit;
}
这个错误解决了什么?
最初调用connect(),其代码为:
public function connect() {
if (empty($this->config['username']) || empty($this->config['password']) || empty($this->config['wsdl'])) {
$this->error = "Your username-password-wsdl must all be set";
$this->showError();
return false;
}
$wsdl = APP.'model/datasource/soapclient/'.$this->config['wsdl'];
$wsdl = str_replace('\\','/',$wsdl);
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection($wsdl);
$mySoapClient = $mySforceConnection->createConnection($wsdl);
$mylogin = $mySforceConnection->login($this->config['username'], $this->config['password']);
$this->client = $mySforceConnection;
return $mySforceConnection;
}
这里在这个函数中你可以看到createConnection和Login被调用...它有代码
public function createConnection($wsdl, $proxy=null) {
$_SERVER['HTTP_USER_AGENT'] = 'Salesforce/PHPToolkit/1.0';
$soapClientArray = null;
if (phpversion() > '5.1.2') {
$soapClientArray = array (
'user_agent' => 'toolkit-php',
'encoding' => 'utf-8',
'trace' => 1,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP
);
} else {
$soapClientArray = array (
'user_agent' => 'toolkit-php',
'encoding' => 'utf-8',
'trace' => 1
);
}
if ($proxy != null) {
$proxySettings = array();
$proxySettings['proxy_host'] = $proxy->host;
$proxySettings['proxy_port'] = $proxy->port; // Use an integer, not a string
$proxySettings['proxy_login'] = $proxy->login;
$proxySettings['proxy_password'] = $proxy->password;
$soapClientArray = array_merge($soapClientArray, $proxySettings);
}
$this->sforce = new SoapClient($wsdl, $soapClientArray);
return $this->sforce;
}
然后登录()
public function login($username, $password) {
$this->sforce->__setSoapHeaders(NULL);
if ($this->callOptions != NULL) {
$this->sforce->__setSoapHeaders(array($this->callOptions));
}
if ($this->loginScopeHeader != NULL) {
$this->sforce->__setSoapHeaders(array($this->loginScopeHeader));
}
$result = $this->sforce->login(array (
'username' => $username,
'password' => $password
));
$result = $result->result;
$this->_setLoginHeader($result);
return $result;
}
这个代码工作得很完美......现在正如我上面提到的,我正在尝试使用帐户模型中的创建方法添加记录。所以首先创建一个名为SforceEnterpriseClient.php的类中调用的方法
public function create($sObjects, $type) {
foreach ($sObjects as &$sobject) {
$sobject = new SoapVar($sobject, SOAP_ENC_OBJECT, $type, $this->namespace);
}
$arg = $sObjects;
return parent::_create(new SoapParam($arg, "sObjects"));
}
这里你可以看到__create被称为ehich在sorceBaseClient类中......
protected function _create($arg) {
$this->setHeaders("create");
return $this->sforce->create($arg)->result;
}
这里首先调用setHeader函数....
private function setHeaders($call=NULL) {
**$this->sforce->__setSoapHeaders(null);** // as I told this line gives error at this point..if I comment it below __setSoapHeaders() gives error.and if I comment that create() function gives error....
$header_array = array (
$this->sessionHeader
);
$header = $this->callOptions;
if ($header != NULL) {
array_push($header_array, $header);
}
if ($call == "create" ||
$call == "merge" ||
$call == "update" ||
$call == "upsert"
) {
$header = $this->assignmentRuleHeader;
if ($header != NULL) {
array_push($header_array, $header);
}
}
if ($call == "login") {
$header = $this->loginScopeHeader;
if ($header != NULL) {
array_push($header_array, $header);
}
}
if ($call == "create" ||
$call == "resetPassword" ||
$call == "update" ||
$call == "upsert"
) {
$header = $this->emailHeader;
if ($header != NULL) {
array_push($header_array, $header);
}
}
if ($call == "create" ||
$call == "merge" ||
$call == "query" ||
$call == "retrieve" ||
$call == "update" ||
$call == "upsert"
) {
$header = $this->mruHeader;
if ($header != NULL) {
array_push($header_array, $header);
}
}
if ($call == "delete") {
$header = $this->userTerritoryDeleteHeader;
if ($header != NULL) {
array_push($header_array, $header);
}
}
if ($call == "query" ||
$call == "queryMore" ||
$call == "retrieve") {
$header = $this->queryHeader;
if ($header != NULL) {
array_push($header_array, $header);
}
}
$this->sforce->__setSoapHeaders($header_array);
}
我无法理解我'创建'是从__create方法传递给setHeader函数..如果我打印$ call(接收参数),它打印“查询”...所以这是我跟踪的代码..
答案 0 :(得分:0)
有什么不清楚的? PHP告诉你,你在一个错误的对象上调用一个函数。这意味着它所说的:__setSoapHeaders()
应该在SoapClient对象上调用,而在你的脚本中则不是。换句话说,$this->sforce
不是SoapClient对象。有关原因,请参阅/显示您的其他代码。
答案 1 :(得分:0)
我遇到了同样的错误,发现原因是我的wsdl xml路径错了 - 你可能想检查这一行:
$ wsdl = APP。&#39; model / datasource / soapclient /&#39;。$ this-&gt; config [&#39; wsdl&#39;];
我现在已经很晚了,但这可能有助于其他人!