Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Can't return scalar values from RPC services #6

Open
edipoReboucas opened this issue Oct 15, 2014 · 6 comments
Open

Can't return scalar values from RPC services #6

edipoReboucas opened this issue Oct 15, 2014 · 6 comments

Comments

@edipoReboucas
Copy link

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.

@TomHAnderson
Copy link

use ZF\ContentNegotiation\ViewModel;

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

@edipoReboucas
Copy link
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?

@TomHAnderson
Copy link

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.

@edipoReboucas
Copy link
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.

@edipoReboucas
Copy link
Author

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

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

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-rpc; a new issue has been opened at laminas-api-tools/api-tools-rpc#3.

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

No branches or pull requests

3 participants