如何在SoapFault访问被拒绝时返回false

时间:2015-03-20 14:20:51

标签: php magento

如何在登录不正确时在SoapFault Access拒绝错误上返回false?

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

如果错误,我需要将false返回到$ sessionId。

1 个答案:

答案 0 :(得分:0)

始终在功能/方法的顶部设置默认返回。 那么只要没有致命的错误/语法错误就会让外部力量变得重要,你会得到一个值:

$vReturn = FALSE;
try
{
    $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
    $sessionId = $proxy->login('apiUser', 'apiKey');
    $vReturn = $sessionId;
}
catch( Exception $oException )
{
    // log?
}
return $vReturn;