【问题标题】:Api-platform (Symfony) : Add data to UrlApi-platform (Symfony) : 将数据添加到 Url
【发布时间】:2020-07-23 22:58:41
【问题描述】:

我遇到了 Api 平台的问题,我开始工作时已经存在的一些代码让我很生气。 这里是:

/**
 * Class PhysicalProfile.
 *
 * @ORM\Table(name="front_user_physical_profile")
 * @ORM\Entity(repositoryClass="App\Repository\PhysicalProfileRepository")
 * @ApiResource(
 *     denormalizationContext={"groups"={"update"}},
 *     collectionOperations={"create"={
 *          "method"="POST",
 *          "path"="/physical-profile",
 *          "access_control"="is_granted('ROLE_USER')"
 *     }, "whoami"={"route_name"="api_security_physicalprofile_whoami"}
 *     },
 *     itemOperations={
 *          "get"={"access_control"="is_granted('ROLE_USER')", "normalizationContext"={"groups"={"null"}}},
 *     }
 * )
 * @ORM\HasLifecycleCallbacks()
 */

我想做的就是像这样在查询中传递一个元素:

/physical-profile/{store}

然后在我的代码中使用它。

除了我在 Api-platform 的文档中找不到任何帮助,这让我想知道我想要的是否可能。 这就是我来这里的原因,想弄清楚是否有人知道这是否可能,以及如何去做。 谢谢!

编辑:store 不是一个 id 而是一个字符串

【问题讨论】:

    标签: php api symfony api-platform.com


    【解决方案1】:

    API 平台期望在像 /physical-profile/{store} 这样的补丁中最后一部分是实体 ID。

    如果您需要查询某些项目,请使用filters

    【讨论】:

    • 除了对我来说 store 不是一个 id 而是一个字符串:/
    • 您的总体目标是什么?你想要 GET 还是 POST 项目?
    • 我想发布项目并在 URL 而不是正文中传递参数,因为我不想将参数存储在数据库中
    • 我认为使用DTOcustom controller 是合适的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    相关资源
    最近更新 更多