?
Solved

assign multiple variables of same name in soap php

Posted on 2012-04-09
4
Medium Priority
?
268 Views
Last Modified: 2016-02-26
I have a soap call which I'm currently successfully making in our system, however I'm only able to query one short_name at a time.
This is the function that calls it.

  public function getCalendarSearch($values)
    {
        $request = new stdClass();
        $request->Channels->DistributionChannel = array("id"=>$this->auth->channelid, "key" => $this->auth->channelkey);
        $request->Providers =  $values["txtShortName"]; //checked short name list
        $request->Query->IndustryCategory = $values["selIndustryCategory"];
        $request->Query->Criteria = array("start_date"=>$values["txtStartDate"], "days"=>$values["txtDays"]);
        //Cache Mode
        if ($values["rdoAuto"] == "on") //Auto
            $request->Query = array("cache"=>"Auto");
            
        if ($values["rdoOn"] == "on") //On
            $request->Query = array("cache"=>"On");
            
        if ($values["rdoOff"] == "on") //Off
            $request->Query = array("cache"=>"Off");
            
        //Show Product Info in results
        if ($values["chkShowProduct"] == "on")
            $request->Response = array("product_calendar"=>true);
        else
            $request->Response = array("product_calendar"=>false);
            
        try {
            echo "<pre>".print_r($request, true)."</pre>";
            $res = $this->v3Client->CalendarSearch($request);
            echo "<pre>".print_r($res, true)."</pre>";
            if($res->Status->Success) {
                return $res->Channels->Channel->Providers->Provider;
            }
            
        } catch (SoapFault $exception) {
            echo $exception;
        }
        
        return null;
    }

Open in new window


The problem however is that we are meant to be able to make calls with the following xml
  <Providers>
    <Provider short_name="Test_ToothnNailLodge" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Black_Jack_Get-A-Way" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="escapegoat_adventures" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="gekko_safari" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Dereks" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Trafalger_House" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="ChateauElan" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Hunter_Resort" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="segenhoe_hotel" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Tea_Gardens" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="BlackJackGetAWay" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
  </Providers>

currently to call it we use something like this

$array = array('Provider' => array('short_name' => 'Naimanya_Cottage'));

Which works well, but we need more than one to be queried at one time. If we have more than one short_name called at the one time, then it would simply reassign the variable.

Does anyone have a workaround for this.

so that we can have it make just one call with multiple Provider-> short_name
presently we are looping through about 10 of these calls which isn't practical really. One call would be much better.

thanks for any help
0
Comment
Question by:paulp75
2 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 37827055
I am not really clear what you want here, but is the following of any assistance? For my own convenience I have loaded the XML as a string to generate an XML object which I process one entry at a time and store all the outputs in a result array keyed by the short name

<?php

/*----- Set up test data ----- */

$data = '<?xml version="1.0" ?>
  <Providers>
    <Provider short_name="Test_ToothnNailLodge" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Black_Jack_Get-A-Way" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="escapegoat_adventures" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="gekko_safari" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Dereks" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Trafalger_House" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="ChateauElan" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Hunter_Resort" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="segenhoe_hotel" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="Tea_Gardens" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
    <Provider short_name="BlackJackGetAWay" xmlns="http://www.v3leisure.com/Schemas/CABS/1.0/CABS_Common.xsd" />
  </Providers>
';


$xml = simplexml_load_string( $data );

$result = array();

/* ----- End of test data set up ----- */





foreach( $xml as $aProvider ) {

     $att = $aProvider->attributes();

     // do SOAP call with $att['short_name'];
     
     $result [$att['short_name'] ] = .... result from SOAP call
}

Open in new window

0
 
LVL 6

Accepted Solution

by:
paulp75 earned 0 total points
ID: 37828426
I finally worked it out
I set the following as $request->Providers->Provider and it worked. thanks for your help anyway
Array
(
    [0] => Array
        (
            [short_name] => Barossa_Shiraz_Estate
        )

    [1] => Array
        (
            [short_name] => Barossa_Trike
        )

    [2] => Array
        (
            [short_name] => stonwellcottages
        )

    [3] => Array
        (
            [short_name] => greenocks_old_telegraph
        )

    [4] => Array
        (
            [short_name] => naimanya_cottage
        )

    [5] => Array
        (
            [short_name] => kooringalhomestead
        )

    [6] => Array
        (
            [short_name] => angel_rest
        )

    [7] => Array
        (
            [short_name] => Eagle_Foundry_Bed_and_Breakfast
        )

    [8] => Array
        (
            [short_name] => Barossa_ShirazEstate
        )

    [9] => Array
        (
            [short_name] => Normas_Place
        )

    [10] => Array
        (
            [short_name] => MiriamsCottage
        )

)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question