【问题标题】:FOSRestBundle View annotation not workingFOSRestBundle 视图注释不起作用
【发布时间】:2013-04-26 20:50:27
【问题描述】:

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"]}

但它不会将状态代码更改为注释中的状态代码。

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

【问题讨论】:

    标签: php rest symfony-2.1 fosrestbundle


    【解决方案1】:

    试试这个:

    use FOS\RestBundle\View\View; 
    

    然后在行动中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      相关资源
      最近更新 更多