Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 504 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FOS rest bundle: unable to find template

#1
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)](

[To see links please register here]

)


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();
}

Reply

#2
Annotate your controller action with `@View` to resolve this issue.

use FOS\RestBundle\View\View;

Have a look at the documentation [chapter View Response listener][1].


----------


If you don't want to annotate every action - you can set the @View annotation for a complete class using [my pull request here][2].

Add this to your composer.json to use the PR.

"require": {
"friendsofsymfony/rest-bundle": "dev-dev-view-addition as 0.12.0",

// ...

"repositories": [
{
"type": "vcs",
"url": "https://github.com/nifr/FOSRestBundle"
},


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
I managed to resolve this issue by setting the listener explicitly to false:

fos_rest:
format_listener: false

**EDIT**

This also works:

fos_rest:
format_listener:
prefer_extension: false
default_priorities:
- json

Reply

#4
(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.
Reply

#5
For FOSRestBundle version 2.0 the config should be

fos_rest:
format_listener:
rules:
prefer_extension: false
fallback_format: json
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through