可能重复:
调试 PHP SOAP 调用
这是我第一次使用soap api,我已经准备了这个脚本,但我得到了
“无法使用 stdClass 类型的对象作为数组”错误,请告诉我检索数据的正确方法
<?php
// Magento login information
$mage_url = 'http://localhost/magento//index.php/api/V2_soap?wsdl=1';
$mage_user = 'rohit';
$mage_api_key = '1234567890';
// Initialize the SOAP client
$soap = new SoapClient( $mage_url );
// Login to Magento
$session_id = $soap->login( $mage_user, $mage_api_key );
print_r($session_id);
?>
<?php
$resources = $soap->resources( $session_id );
if( is_array( $resources ) && !empty( $resources )) { ?>
<?php foreach( $resources as $resource ) { ?>
<h1><?php echo $resource['title']; ?></h1>
Name: <?php echo $resource['name']; ?><br/>
Aliases: <?php echo implode( ',', $resource['aliases'] ); ?>
<table>
<tr>
<th>Title</th>
<th>Path</th>
<th>Name</th>
</tr>
<?php foreach( $resource['methods'] as $method ) { ?>
<tr>
<td><?php echo $method['title']; ?></td>
<td><?php echo $method['path']; ?></td>
<td><?php echo $method['name']; ?></td>
<td><?php echo implode( ',', $method['aliases'] ); ?></td>
</tr>
<?php } ?>
</table>
<?php } ?>
<?php } ?>