Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOS rest bundle: unable to find template

I get the exception:

Unable to find template ""

The other similar questions didn't help; and weirdly enough it was working fine and then suddenly started giving me this exception.

composer:

   "friendsofsymfony/rest-bundle": "0.13.*@dev",
   "jms/serializer-bundle": "0.12.*@dev",

I'm following Automatic route generation: single RESTful controller (for simple resources)

config:

fos_rest:
    format_listener: true
    routing_loader:
        default_format: json
    view:
        view_response_listener: 'force'
    serializer:
        serialize_null: true

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

routing:

sectors:
    type: rest
    prefix: /{v}
    resource: JJ\MainBundle\Controller\SectorsController

controller:

/**
 * @RouteResource("Sector")
 */
class SectorsController extends Controller
...
    public function cgetAction()
    {
        return $this->getSectorIndustryRepo()->findAll();
    }
like image 672
Tjorriemorrie Avatar asked Aug 02 '13 07:08

Tjorriemorrie


2 Answers

(For reference) If One is testing with a rest client or manually be sure to set the header in your request: Accept:application/json

Because fosRestBundle tries to determine the proper response type from the headers in the request.

like image 114
le0diaz Avatar answered Sep 16 '22 15:09

le0diaz


For FOSRestBundle version 2.0 the config should be

fos_rest:
    format_listener:
        rules:
            prefer_extension: false
            fallback_format: json
like image 37
Lunin Roman Avatar answered Sep 16 '22 15:09

Lunin Roman