Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

assign multiple variables of same name in soap php

Posted on 2012-04-09
4
Medium Priority
?
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

647 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