我收到此错误:
致命错误:在第 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 帐户中添加帐户详细信息。所以我将以下代码放在我的 Account 模型中只是为了测试,可能会产生任何问题:
$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(接收到的参数),它会打印“查询”……所以这是我追踪的代码……