Using PHP and SoapClient.
I need to pass the following XML into a soap request - i.e. multiple
\'s within
.
I also had this problem and found the solution. Stays needs to be an array with ascending keys starting with 0.
$client = new SoapClient('http://myservice.com?wsdl');
$stays[] = array('startDate'=>'01-01-2013', 'endDate'=>'02-02-2013');
$stays[] = array('startDate'=>'02-02-2013', 'endDate'=>'03-03-2013');
$params = array(
'reservation' => array('stays'=>$stays)
);
$client->saveReservation($params);
I found my answer on this page: https://bugs.php.net/bug.php?id=45284
I had similar problem and I had to post data in this structure. Accepted answer didn't work for me
$xml = array('reservation' => array(
'stays' => array(
array(
'start_date' => '2011-01-01',
'end_date' => 2011-01-15
),
array(
'start_date' => '2011-01-01',
'end_date' => 2011-01-15
)
)
));
maybe it might help somebody if accepted answear doesn't work for you
+ minor tip for all of you, use $xml = ['key' => 'val'];
instead of $xml = array('key' => 'val');
Assuming that when you instantiated $soapClient
, you did so in WSDL mode, the following should work:
$stay1 = new stdClass();
$stay1->start_date = "2011-01-01";
$stay1->end_date = "2011-01-15";
$stay2 = new stdClass();
$stay2->start_date = "2011-01-01";
$stay2->end_date = "2011-01-15";
$stays = array();
$stays[0] = $stay1;
$stays[1] = $stay2;
$soapClient->saveReservation(
array("reservation" => array("stays" => $stays))
);
I also ran into this issue calling soap with an parameter as an array. My array has to start with index 0 for it to work.
$client->__soapCall(my_function_name, [
'body' => [
'date' => '201930',
'ids' => [0 => '32001', 1 => '32002'],
],
]);
Try this:
$xml = array(
'stays' => array(
'stay' => array(
array( /* start end */ ),
array( /* start end */ ),
array( /* start end */ )
)
)
);
'stay' has to be defined just once. This should be the right answer:
$xml = array('reservation' => array(
'stays' => array(
'stay' => array(
array(
'start_date' => '2011-01-01',
'end_date' => 2011-01-15
),
array(
'start_date' => '2011-01-01',
'end_date' => 2011-01-15
)
)
)
));