Search code examples
phpsymfonyfosrestbundle

Parent attribute is not allowed


Based on this example: http://npmasters.com/2012/11/25/Symfony2-Rest-FOSRestBundle.html

I tried to use a parent in a FOSRestBundle implementation. The problem however is that it seems that the parent attribute is not recognized or not supported any more. Any advise?

bla_rest_api_Location:
    type: rest
    parent: bla_rest_api_User
    resource: Bla\RestUserBundle\Controller\LocationController

Exception:

 [Symfony\Component\Config\Exception\FileLoaderLoadException]
 Cannot import resource "C:\xampp\htdocs\EntisServer\src\VSmart\RestUserBund
 le/Resources/config/routing.yml" from "C:/xampp/htdocs/EntisServer/app/conf
 ig\routing.yml". (The routing file "C:\xampp\htdocs\EntisServer\src\VSmart\
 RestUserBundle/Resources/config/routing_generated.yml" contains unsupported
  keys for "v_smart_rest_api_Location": "parent". Expected one of: "resource
 ", "type", "prefix", "pattern", "path", "host", "schemes", "methods", "defa
 ults", "requirements", "options", "condition".)

Solution

  • I vaguely remember something about the resource linking to the file that contains these resources needing to be of type rest (so the link your VSmartRestUserBundle:routing resources in app/config/routing.yml would need to have the type rest).

    I may be wrong though, I didn't really use the parent feature.

    In fact it is stated here.

    Notice parent: users option in the second case. 
    This option specifies that the comments resource is child of the users resource.
    
    It is also necessary to add type: rest to the routing.yml file:
    
    # app/config/routing.yml
    acme_hello:
        type: rest
        resource: "@AcmeHelloBundle/Resources/config/users_routes.yml"