I have been creating REST API using symfony4, I have installed FosRestBundle and I configured it to return object directly from the controller.
I want to return an object from the controller but I get the error
Warning: ReflectionObject::__construct() expects parameter 1 to be object, null given
MoviesController:
/**
* @Rest\View()
* @Route("/movies", name="get_movies")
*
*/
public function getMovies()
{
$movies = $this->getDoctrine()
->getRepository(Movie::class)
->findAll();
return $movies;
}
fos_rest.yaml:
fos_rest:
param_fetcher_listener: force
body_converter:
enabled: true
view:
formats: { json: true, xml: false, rss: false }
view_response_listener: true
serializer:
serialize_null: true
format_listener:
rules:
- { path: '^/', priorities: ['json'], fallback_format: 'json' }
framework.yaml
sensio_framework_extra:
view: { annotations: false }