我是API平台框架的新手,对于我正在开发的项目,我们需要使用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。
我错过了什么?
谢谢!
API-Platform 2.4.0-beta的更新解决了这个问题