SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php and WS - array with one row

    For example I have WebService function which returns:

    A. array with more than 1 row:
    PHP Code:
    $ws->item[0]->id 99;
    $ws->item[0]->name 'test';
    $ws->item[1]->id 99;
    $ws->item[1]->name 'test';
    return 
    $ws
    PHP converts it to:
    Code:
    stdClass Object ( [item] => Array ( [0] => stdClass Object ( [id] => 99 [name] => 'test' ) [1] => stdClass Object ( [0] => stdClass Object ( [id] => 99 [name] => 'test' ) ) )
    So it is array - correct - I can use foreach to iterate throw elements.

    B. array with 1 row:
    PHP Code:
    $ws->item[0]->id 99;
    $ws->item[0]->name 'test';
    return 
    $ws
    PHP converts it to:
    Code:
    stdClass Object ( [item] => stdClass Object ( [id] => 99 [name] => 'test' ) )
    So it isn't ARRAY - I can't using in that case foreach to iterate throw elements.

    So I must always write duplicate code (to get elements) for array with 1 row and more than 1 row ??

  2. #2
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is part of my file wsdl:
    Code:
    <xsd:element name="items" type="itemsType" />
    	      
    	        <xsd:complexType name="itemsType">
    			  <xsd:complexContent>
    			    <xsd:restriction base="SOAP-ENC:Array">
    			      <xsd:sequence>
    			        <xsd:element name="id" type="xsd:string" maxOccurs="unbounded"/>
    			      </xsd:sequence>
    			    </xsd:restriction>
    			  </xsd:complexContent>
    		    </xsd:complexType>
    		    
    		    
    		    <xsd:element name="result" type="xsd:string" />

    Server:
    PHP Code:
    function search($tab)
        {
            return 
    print_r($tabtrue); 
        }

        
    $server = new SoapServer('http://localhost:82/soap_test/wsdl/wsdl.php'); 
        
    $server->addFunction("search"); 
        
    $server->handle(); 


    client:
    PHP Code:
    $tab_ws->id[0] = 'a235g';
            
    //$tab_ws->id[1] = 'b68fg';
                             
            
    $client = new SoapClient('http://localhost:82/soap_test/wsdl/wsdl.php');
            
    $tab $client->search($tab_ws);    
            
    print_r($tab); 
    Client show me result:
    Code:
    stdClass Object ( [id] => a235g )
    But I need result:
    Code:
    stdClass Object ( [id] => Array ( [0] => a235g ) )
    What am I doing wrong ?

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,156
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Any better if you change
    Code XML:
    <xsd:element name="id" type="xsd:string" maxOccurs="unbounded"/>
    to xsd:array ??

  4. #4
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <xsd:element name="id" type="xsd:array" maxOccurs="unbounded"/>
    ?? Still the same problem


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •