API 自定义操作中的 PLATFORM 自定义标识符

API PLATFORM custom identifier in custom action

我想在自定义操作中使用自定义标识符,而不是像这样使用 {id}。

 @ApiResource(
   itemOperations={
     "FORGOT-PASSWORD"={
        "method"="PUT",
        "path"="/users/{forgotPasswordToken}/forgot-password",
        "controller"="App\Controller\ForgotPasswordController",
        "defaults"={"identifiedBy"="forgotPasswordToken"}
        }
    }
  )

但我仍然遇到与 "Invalid identifier value or configuration" 相同的错误。

有什么问题吗?

这是因为 Api 平台有一个读取侦听器,它尝试检索实体 link 到您的项目操作。

对于您的自定义操作,您的路径中没有像 {id} 这样的标识符来标识您的资源,因此解决方案是使用类似这样的东西来停用读取侦听器:

@ApiResource(
   itemOperations={
     "FORGOT-PASSWORD"={
        "method"="PUT",
        "path"="/users/{forgotPasswordToken}/forgot-password",
        "controller"="App\Controller\ForgotPasswordController",
        "defaults"={"identifiedBy"="forgotPasswordToken"},
        "read"=false
        }
    }
  )