FOSRestBundle视图注释不起作用


FOSRestBundle View annotation not working

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
}

如果我用.json格式访问路由,它返回:

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

但是它不会将状态码更改为来自annotation的状态码。

同样没有指定的格式,它不会回退到默认的.json格式,它仍然搜索模板

试试这个:

use FOS'RestBundle'View'View; 

然后在动作中:

$view = View::create($response, 204);
return $view;