0

config.yml:

fos_rest:
    param_fetcher_listener: true
    body_listener: true
    format_listener: 
        default_priorities: [json, xml]
    view:
        view_response_listener: 'force'  

sensio_framework_extra:
    view:    { annotations: false }
    router:  { annotations: true }

annotated controller:

/**
 * @Rest\View(statusCode=204)
 * @param \Symfony\Component\HttpFoundation\Request $request
 */
public function signUpAction(Request $request)
{
    return $this->get('%%%.response_generator')->generateResponse(array('test'), true, 'test'); 
    // returns a simple Object with some public properties
}

If I access the route with .json format it returns:

{"status":1,"message":"test","data":["test"]}

But it won't change the status code to the one from annotation.

Also without a specified format, it doesn't fallback to the default .json format, it still searches for a template.

user1236048
  • 5,542
  • 7
  • 50
  • 87

1 Answers1

2

Try this:

use FOS\RestBundle\View\View; 

And then in the action:

$view = View::create($response, 204);
return $view;
Baba Yaga
  • 1,819
  • 15
  • 20