yii_king
(Micho23)
August 6, 2012, 7:52am
1
I have created a web service with Yii and am testing it with soapUi as the client. My main problem is to figure out how to pass the attribute names of each field. I get the values and I can work with them as long as the order of them is exactly how I want it. But is there any way to control attribute names in arrays? Example: I want the tag "id" within datalist to be passed to the controller. It works for the Strings defined, but not for tags in the array. Can anyone point me in the right direction?
Below you can see the client call:
<soapenv:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soapenv="" xmlns:urn="urn:MeteReadingsControllerwsdl">
<soapenv:Header/>
<soapenv:Body>
<urn:meterReadings soapenv:encodingStyle="">
<username xsi:type="xsd:string"></username>
<password xsi:type="xsd:string"></password>
<datalist>
<id>abc</id>
</<datalist>
</urn:meterReadings>
</soapenv:Body>
</soapenv:Envelope>
And the method retrieving it is like this:
/**
* @param string the username for the webservice
* @param string the password for the webservice
* @param array with values sent from client
* @return array the status
* @soap
*/
public function updateMeterReadings($username, $password, $datalist)
{
// Login before proceeding
// Add code here
// Add all input parameters to an array
if (isset($datalist)) {
$input = array();
foreach ($datalist as $key => $val) {
$input = $this->array_push_assoc($input, $key, $val);
}
}
else {
$output = array(
"status" => false,
"errorMessage" => "All fields are required",
);
return $output;
}
$model=new MeterReadings;
if(isset($input))
{
// Validate the input
$model->attributes=$input;
// If save is possible return true and an empty error message
if($model->save()) {
$output = array(
"status" => true,
"errorMessage" => "",
);
return $output;
}
else {
// If the data could not be saved, return false and an explicit error message
$output = array(
"status" => false,
"errorMessage" => $model->getErrors(),
);
return $output;
}
}
}