找不到常量子资源操作,类应用\实体\注释



我有两个表评论和作者之间的OneToMany关系,我想显示评论的作者,但它给了我错误[Semantical Error] Couldn't find constant subresourceOperations, class AppEntityCommentsrc 实体 Comment.php

<?php
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use AppRepositoryCommentRepository;
use SymfonyComponentSerializerAnnotationGroups;
use DoctrineORMMapping as ORM;

/**
* @ApiResource(itemOperations={"GET","DELETE",
*       "PUT"={
*         "access_control"="is_granted('IS_AUTHENTICATED_FULLY') and object.getAuthor() == user"
*        }
*      },
*  collectionOperations={"GET",
*    "POST"={
*         "access_control"="is_granted('IS_AUTHENTICATED_FULLY')"
*       },
*   subresourceOperations={
*     "api_posts_comments_get_subresource"={
*        "normalization_context"={
*            "groups"={"get-comment-with-author"}
*           }
*         }
*        }     
*       }
*)
* @ORMEntity(repositoryClass=CommentRepository::class)
*/

正如@julien B所说,你必须关闭"collectionOperations"括号"}";并将itemOperations、collectionOperations和subresourceOperations放在同一级别

namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use AppRepositoryCommentRepository;
use DoctrineORMMapping as ORM;
use SymfonyComponentSerializerAnnotationGroups;
/**
* @ApiResource(
*    itemOperations={"GET", "DELETE", 
*      "PUT"={
*            "access_control"="is_granted('IS_AUTHENTICATED_FULLY') and object.getAuthor() == user"
*      }
*    },
*    collectionOperations={
*         "GET", 
*         "POST"={
*            "access_control"="is_granted('IS_AUTHENTICATED_FULLY')"
*         }
*    },
*    subresourceOperations={
*        "api_posts_comments_get_subresource"={
*            "normalization_context"={
*                "groups"={"get-comment-with-author"}
*            }
*        }
*    }
* )
* @ORMEntity(repositoryClass=CommentRepository::class)
*/
class Comment

相关内容

  • 没有找到相关文章

最新更新