首页 > 解决方案 > Api-platform (Symfony) : 将数据添加到 Url

问题描述

我遇到了 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 而是一个字符串

标签: phpapisymfonyapi-platform.com

解决方案


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

如果您需要查询某些项目,请使用过滤器


推荐阅读