-1

I have the following configuration:

fos_rest:
    view:
        view_response_listener: 'force'
        formats:
          json: true
          xml: true
          html: false
    body_listener:
        decoders:
            json: fos_rest.decoder.json
            xml: fos_rest.decoder.xml
    body_converter:
        enabled: true
    format_listener:
        enabled: true
        rules:
          - { path: '^/api', priorities: ['xml', 'json'], fallback_format: xml, prefer_extension: false }
    param_fetcher_listener: force
    routing_loader:
#        default_format: xml
        include_format: false
    serializer:
        serialize_null: true

and the following Controller:

/**
 * @Rest\View(serializerGroups={"o-all-getCDashboard"})
 */
public function cgetAction($_format)
{
    $handler = $this->getHandler();
    die(dump($_format));

    return $handler->getAll();
}

within a class that extends FOSRestController implements ClassResourceInterface

which always dumps null. If I re-enable default_format: xml what I get is always xml notwithstanding the Accept header I send. What's wrong with it? Why does not the format_listener work?

Bertuz
  • 2,390
  • 3
  • 25
  • 50

1 Answers1

1

You using uncorrected format_listeners config. Try using my config like this:

fos_rest:
    body_listener: true
    param_fetcher_listener: true
    view:
        view_response_listener: 'force'

        formats:
            jsonp: true
            json: true
            xml: false
            rss: false
        mime_types:
            json: ['application/json', 'application/x-json']
            jpg:  ['image/jpeg']
            png:  ['image/png']
        jsonp_handler: ~
    routing_loader:
        default_format:  json
        include_format:  false
    format_listener:
        rules:
            - { path: /api, priorities: [ json, jsonp ], fallback_format: json, prefer_extension: true }
    exception:
        enabled: true

Addition just settings section formats and fallback_format for yourself. In my controller I using

use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\RouteResource;

/**
* @RouteResource("someName")
*/
class myController extends FOSRestController implements ClassResourceInterface {

    /**
     * @param Request $request
     * @Rest\Post("/someLink")
    */
   public function insertLinkAction(Request $request) {}
}

I hope that help you.

Rider_BY
  • 1,129
  • 1
  • 13
  • 31