[英]Symfony and API Platform - retrieving data by slug or userToken or any other field different than ID
What I'm trying to do is:我想要做的是:
So I've defined:所以我定义了:
* @ApiResource(itemOperations={
* "get",
* "activate_account"={
* "method"="get",
* "path"="/account/activate/{confirmationToken}",
* "controller"=UserActivate::class
* }
* })
*/
In my User
entity class there is UserActivate
controller and UserActivateHandler
that is invoked by UserActivate
controller.在我的User
实体类中,有UserActivate
控制器和UserActivateHandler
由UserActivate
控制器调用。 I've set ApiProperty
identifier
for ID to false
and for confirmationToken
to true
.我给自己定ApiProperty
identifier
的ID,以false
和confirmationToken
至true
。
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @ApiProperty(identifier=false)
*
*/
private $id;
/**
*
* @ORM\Column(type="string", nullable=true)
* @ApiProperty(identifier=true)
*/
protected $confirmationToken;
However API Platform still requires an ID and it doesn't seem to see confirmationToken
parameter.但是 API 平台仍然需要一个 ID,它似乎没有看到confirmationToken
参数。
Basically my question is, how I can retrieve an object by, in this case, confirmationToken
?基本上我的问题是,我怎么能检索由一个对象,在这种情况下, confirmationToken
?
I had the same problem, getting an entity by a different property than the one indicated as the identifier;我遇到了同样的问题,通过与标识符指示的属性不同的属性获取实体; you did well with the property annotations:您在属性注释方面做得很好:
@ApiProperty(identifier=false)
@ApiProperty(identifier=true)
but at the same time you have to mantain the {id} in your path, so change但同时你必须在你的路径中保持 {id},所以改变
"path"="/account/activate/{confirmationToken}",
to到
"path"="/account/activate/{id}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.