Php 使用GET方法为集合创建自定义路由
我无法为集合创建自定义路由,我的实体名为File 这是我的实体注释:Php 使用GET方法为集合创建自定义路由,php,symfony,doctrine-orm,api-platform.com,Php,Symfony,Doctrine Orm,Api Platform.com,我无法为集合创建自定义路由,我的实体名为File 这是我的实体注释: /** * @ApiResource( * * normalizationContext={"groups"={"file"},"enable_max_depth"=true}, * denormalizationContext={"groups"={"file-write-customers"},"enable_max_depth"=true}, * attributes={"force_e
/**
* @ApiResource(
*
* normalizationContext={"groups"={"file"},"enable_max_depth"=true},
* denormalizationContext={"groups"={"file-write-customers"},"enable_max_depth"=true},
* attributes={"force_eager"=false},
* itemOperations={
* "get",
* "put",
* "get_mandate_pdf"={
* "method"="POST",
* "path"="/files/{id}/mandate-pdf",
* "controller"=FileCreatePdfController::class,
* },
* },
* collectionOperations={
* "stats"={
* "method"="GET",
* "path"="/files/stats",
* "controller"=FileStatsController::class,
* }
* },
* )
* @ApiFilter(SearchFilter::class, properties={"status": "exact", "sponsor": "exact"})
* @ApiFilter(DateFilter::class, properties={"updatedAt"})
* @ORM\Entity
* @ORM\Table(name="cases")
*/
控制器文件
<?php
namespace App\Controller;
use App\Entity\File;
class FileStatsController
{
public function __invoke(File $data): File
{
return $data;
}
}
如果删除类型化变量$data,我会设法在控制器中找到解决方案 名称空间App\Controller
class FileStatsController
{
public function __invoke($data)
{
return $data;
}
}
我设法正确地检索了数据
此外,方法get在ApireSource注释中是必需的
collectionOperations={
"get",
* "stats"={
* "method"="GET",
* "path"="/stats",
* "controller"=FileStatsController::class,
* }
* }
看起来,获取路径“FileStatsController::class”的控制器操作需要一个“id”才能从存储库中获取实体,至少条令消息是这样说的$yourRepository->find(空);
collectionOperations={
"get",
* "stats"={
* "method"="GET",
* "path"="/stats",
* "controller"=FileStatsController::class,
* }
* }