duankuai6586 2014-10-18 21:39
浏览 25

如何为Symfony 2添加自动嵌套资源路由?

I have to admit I am very new to Symfony. In fact, I just started a few hours ago. I successfully did this tutorial and I wanted to see if it would also do nested routing automatically.

So I created another entity User (using FOSUserBundle) and I modified the entity Post to have a reference to the User. So now when I go to http://localhost:8000/api/posts/1 I get this nice json:

{
    "id":1,
    "user":{     
        "id":1,
        "username":"Evert",
        "username_canonical":"evert",
        "email":"blabla@gmail.com",
        "email_canonical":"blabla@gmail.com",
        "enabled":true,
        "salt":"prxnqb681340c080g0k0g0owgkocsow",
        "password":"nTuI7GFL1yLIFlecWHHC58Lxi\/XjTu2dNoz4l3YGUuUhU+OH6JQFpv\/ojlfXOxoNmjgDdX9CsXTvzRGJi1PbzQ==",
        "last_login":"2014-10-18T23:25:04+0200",
        "locked":false,
        "expired":false,
        "roles":[],
        "credentials_expired":false
    },
    "name":"First!",
    "description":"Dus..."
}

Now I was hoping that if I would go to http://localhost:8000/api/posts/1/user that I would get to see the user that is connected to post, but by itself. However that's not the case. And I have tried to Google for how to do this, but I couldn't find anything. I think I could do it completely manually, but I would prefer if this nesting of resources is automatically available.

Can anybody tell me how I can make this routing work automatically for all related resources?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line