我对应用程序接口平台框架是个新手,对于我正在从事的项目,我们需要使用mongoDb。
我按照使用mongoDb (see here)进行设置的说明进行了操作。但是我安装了doctrine/mongodb-odm:2.0.x.-dev而不是doctrine/mongodb-odm:^2.0.0@beta,这样bin/console doctrine:mongodb:schema:create命令就可以工作了……
在任何情况下,我都根据提供的示例创建了一个非常简单的文档:
<?php
// api/src/Document/Test.php
namespace App\Document;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource
*
* @ODM\Document
*/
class Test
{
/**
* @ODM\Id(strategy="INCREMENT", type="integer")
*/
private $id;
/**
* @ODM\Field(type="string")
* @Assert\NotBlank
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}但是,我得到的响应是:"Unable to generate an IRI for the item of type \"App\\Document\\Test\""。但正如您所看到的,ID-getter函数就在那里,这似乎是导致错误的“常见”原因。
完整的响应正文可以在in this pastebin中找到。
我遗漏了什么?
谢谢!
发布于 2019-02-20 15:42:33
API-Platform 2.4.0-beta的更新解决了这个问题
https://stackoverflow.com/questions/54762183
复制相似问题