Jak*_*kub 5 php api doctrine symfony api-platform.com
我想做的是:
所以我定义了:
* @ApiResource(itemOperations={
* "get",
* "activate_account"={
* "method"="get",
* "path"="/account/activate/{confirmationToken}",
* "controller"=UserActivate::class
* }
* })
*/
Run Code Online (Sandbox Code Playgroud)
在我的User实体类中有一个UserActivate控制器,并由控制器UserActivateHandler调用UserActivate。我已将ApiProperty identifierID设置false为 to 和confirmationTokento 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;
Run Code Online (Sandbox Code Playgroud)
但是API Platform仍然需要ID并且它似乎没有看到confirmationToken参数。
基本上我的问题是,在这种情况下,我如何检索对象confirmationToken?
小智 1
我遇到了同样的问题,通过与标识符指示的属性不同的属性获取实体;您在属性注释方面做得很好:
@ApiProperty(identifier=false)
@ApiProperty(identifier=true)
Run Code Online (Sandbox Code Playgroud)
但同时你必须在你的路径中保留 {id} ,所以改变
"path"="/account/activate/{confirmationToken}",
Run Code Online (Sandbox Code Playgroud)
到
"path"="/account/activate/{id}"
Run Code Online (Sandbox Code Playgroud)