无法在非对象上获取属性-API平台

时间:2018-10-09 10:52:21

标签: api-platform.com

相关帖子=> how to debug " "Unable to get a property on a non-object." in custom operations?

你好, 我有同样的问题。吼叫,我的配置

/**
 * @ORM\Entity
 * @ApiResource(iri="http://schema.org/MediaObject",
 *     collectionOperations={
 *         [...]
 *          "post"={
 *              "access_control"="object.owner == user",
 *              "access_control_message"="Only owner can access entity.",
 *              "method"="POST",
 *              "path"="/media_objects",
 *              "controller"=CreateMediaObjectAction::class,
 *              "defaults"={"_api_receive"=false}
 *          }
 *     },
 *     [...]
 *     }
 * )
 * @Vich\Uploadable
 */
class MediaObject {
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var File|null
     * @Assert\NotNull()
     * @Vich\UploadableField(mapping="media_object", fileNameProperty="contentUrl")
     */
    public $file;

    /**
     * @var string|null
     * @ORM\Column(nullable=true)
     * @ApiProperty(iri="http://schema.org/contentUrl")
     * @Groups({"story"})
     */
    public $contentUrl;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
     * @ORM\JoinColumn(nullable=false)
     */
    private $owner;

    [...]

当我想要POST MediaObject时,我遇到了相同的错误。

{
  "@context": "/.../api/public/api/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Unable to get a property on a non-object.",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/home/.../api/vendor/symfony/expression-language/Node/GetAttrNode.php",
      "line": 73,
      "args": []
    },

当我删除object.owner安全性时,这很好。有什么办法吗? 我有另一个带有此安全注释的实体,没有麻烦。 非常感谢你, 纪尧姆

0 个答案:

没有答案