【问题标题】:Cannot use object of type stdClass as array magento [duplicate]不能将 stdClass 类型的对象用作数组 magento [重复]
【发布时间】:2013-02-04 12:19:43
【问题描述】:

可能重复:
Debugging PHP SOAP call

这是我第一次使用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 } ?> 

【问题讨论】:

    标签: php api magento soap


    【解决方案1】:

    你在哪一行得到错误?

    http://php.net/manual/ru/function.get-object-vars.php

    $array = get_object_vars($object);
    

    【讨论】:

      猜你喜欢
      • 2012-03-29
      • 2011-10-12
      • 2013-05-11
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      相关资源
      最近更新 更多