Search code examples
phprestsymfonyfosrestbundle

Symfony2 FOS Rest bundle routing FileLoaderLoadException controller


I have a very strange issue, with my Symfony2 setup.

I'm working on a restful webservice and would like to setup routing.

I have a fully working application and woud like to change my routing.yml config.

Working configuration

my_product:
    resource: My\Bundle\ProductBundle\Controller\DefaultController
    type:     rest
    prefix:   /

When I change that to:

my_product:
    resource: "@MyProductBundle/Controller/"
    type:     rest
    prefix:   /

I get the following error:

Symfony\Component\Config\Exception\FileLoaderLoadException" message="Can't find class for controller "@MyProductBundle/Controller/" in @MyProductBundle/Controller/ (which is being imported from "/home/myproduct/domains/example/v5/app/config/routing.yml"). Make sure the "MyProductBundle" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "@MyProductBundle/Controller/" is not empty.

When I change the type from "rest" to "annotation", the error disappears.

What am I doing wrong? I can't find it out and my searches lead to nothing.

Many thanks in advance!


Solution

  • You can't currently import all of a bundle's controllers at once when using FOSRestBundle. It will be added in FOSRestBundle 2.0. Import your controllers individually like in your first example.

    enter image description here