Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response in single and many results #34

Closed
stistoyanov opened this issue Sep 5, 2015 · 2 comments
Closed

Response in single and many results #34

stistoyanov opened this issue Sep 5, 2015 · 2 comments

Comments

@stistoyanov
Copy link

Hello I really liked the flexibility of this Soap Client Plugin but I am a PHP developer and I could not figure out why the response returns different result if one or many appear. I searched a lot and found only one correct answer and I fixed it for myself here is the question that other dev asked more explanatory:
response with one:
object(stdClass)#2 (1) {
["return"]=>
object(stdClass)#3 (1) {
["row"]=>`
object(stdClass)#4 (1) {
["pkid"]=>
string(36) "9dbd9b32-8d64-41ad-a355-8f62e050ffce"
}
}
}
with more than one:
object(stdClass)#2 (1) {
["return"]=>
object(stdClass)#3 (1) {
["row"]=>
array(2) {
[0]=>
object(stdClass)#4 (1) {
["pkid"]=>
string(36) "fa0540f7-8e75-481b-a193-7a06d7f601a8"
}
[1]=>
object(stdClass)#5 (1) {
["pkid"]=>
string(36) "fa0c8c7a-79be-4667-ae70-c3e773908b52"
}
}
}
}

and to see why this is a problem:
for one:
foreach ($response->return as $row){
var_dump($row->pkid);
}

for more than one:
foreach ($response->return->row as $row){
var_dump($row->pkid);
}

So after I saw that's my case I simply added the 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS function to the controllers approach in the options:
.....
->options(['login' => 'username', 'password' => 'password', 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS]);
.....

This fixed the problem and now every response no mater if one or many, returns properly.
I think it is really strange that it was hard to find why this was happening and I'm just presenting you this matter to review.

@notfalsedev
Copy link
Owner

Thank you for the information.

@marnickmenting
Copy link

Thanks a lot, this helped me in getting the returned results always in an array so I can always process them in the same manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants