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

Can't return scalar values from RPC services #3

Open
weierophinney opened this issue Dec 31, 2019 · 5 comments
Open

Can't return scalar values from RPC services #3

weierophinney opened this issue Dec 31, 2019 · 5 comments

Comments

@weierophinney
Copy link
Contributor

Today I try return a integer from my rpc service and apigility return a html page without a error.

I see that top level parser is different from deep level parser, for example:

this code
return array(array(1));
return this json
{"0":[1]}

Maybe the problem has something relative to this, sometime that top leve parser try convert everthing to a object.


Originally posted by @edipoReboucas at zfcampus/zf-rpc#6

@weierophinney
Copy link
Contributor Author

use ZF\ContentNegotiation\ViewModel;

return new ViewModel([0 => 1]);


Originally posted by @TomHAnderson at zfcampus/zf-rpc#6 (comment)

@weierophinney
Copy link
Contributor Author

This return a object, not a array like expected.
this code
return new \ZF\ContentNegotiation\ViewModel(array(0 => 1))

return this json
{"0":1}

I expected this
[1]

Using a integer:

return new \ZF\ContentNegotiation\ViewModel(1)

I receive this error:

... "detail":"Zend\\View\\Model\\ViewModel::setVariables: expects an array, or Traversable argument; received \"integer\""}

This is the projected behavior?


Originally posted by @edipoReboucas at zfcampus/zf-rpc#6 (comment)

@weierophinney
Copy link
Contributor Author

The error is correct. If your calling process needs a scalar value and cannot process the json you could, and I'm not recommending you do this, put a die(1); at the end of your procedure.


Originally posted by @TomHAnderson at zfcampus/zf-rpc#6 (comment)

@weierophinney
Copy link
Contributor Author

I guess that a better behavior is if the array is a hashmap use the current top level parser, in another cases use the deep level parser. Is very ugly the current behavior.


Originally posted by @edipoReboucas at zfcampus/zf-rpc#6 (comment)

@weierophinney
Copy link
Contributor Author

By now I using this solution to not break the flow of the framework.

return $this->getResponse()->setContent(Json::encode($result));


Originally posted by @edipoReboucas at zfcampus/zf-rpc#6 (comment)

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

1 participant