1

there a tons of tutorials on the web about how to set the action-response to type json in a symfony controller. But how can I receive JSON?

$request->getRequestFormat() returns "json", but the json data seems to be lost, because $request->getParameter() doesn't work.

This is my routing:

importservice:
  url: /importservice
  class: sfRequestRoute
  param: { module: remoteaccess, action: import, sf_format: json }
  requirements:
    sf_method: post
    sf_format: json

Edit:

getParameter() decodes multipart/form-data (html-forms) and get-parameters, so I thought it also does this for content-type application/json. I need this for a web-service which posts data. My basic idea was that it makes no difference whether a human fills out html-forms or a bot sends the data directly. I thought that encoding the content to json is easier to implement than encoding it to multipart/form-data.

2
  • It's unclear what you mean, please elaborate. Commented Jan 27, 2011 at 18:28
  • Why do you need to send data in JSON? Commented Jan 28, 2011 at 5:25

1 Answer 1

1

I came to this conclusion:

Symfony's getParameter() method provides GET-parameters (url) and parameters which are defined in the routing (uri). The items of multipart data will also be provided, because this media-type is just a container for sub-content packages, whereas application/json is already the content itself. In other words: multipart just declares that there is more than one content-package.

One might claim that json is also a data-container, but I think that multipart contains data on the "http-level", whereas json contains data on the "content-level".

The confusion arises by the fact that multipart is actually something like a meta-media-type.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.