Solved

assign multiple variables of same name in soap php

Posted on 2012-04-09
4
242 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
4 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Generate PDF from MySQL using PHP 3 54
xml with php question 5 35
PHP Underscores vs. Directory separators 5 28
How do i use the await event in php echo 5 18
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to dynamically set the form action using jQuery.

749 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