我正在使用symfony2 API平台从我的mongodb数据库中生成api,但是我得到了以下错误:hydra:description:“找不到”AppBundle\Document\ “类型对象的资源
我有两个mongo文档用户和一个文章,每个用户都有多个文章,所以我试图列出所有用户的所有文章标题,这样我就可以得到如下内容:
{
@id: "/user/53edb6200cf2400d584c2617",
@type: "user",
class: "de.freelancer.mongo.domain.User",
email: "feer@de.com",
displayname: "feer",
withnewsletter: false,
language: "de_DE",
active: true,
admin: false,
articles : ['article1','article2','article3']
}这是我的代码:
用户文档
<?php
namespace AppBundle\Document;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Validator\Constraints as Assert;
/**
@MongoDB\Document
@MongoDB\Document(collection="user")
/
class User{
    /*
    @MongoDB\Id(strategy="AUTO") */ 
    private $id;
    /**
    @MongoDB\ReferenceMany(targetDocument="articles", mappedBy="user") */
    private $articles;
    public function __construct()
    {
        $this->articles = new ArrayCollection();
    }
    /**
    */
    public function getArticles()
    {
        return $this->articles;
    }
}文章文档
<?php
namespace AppBundle\Document;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Validator\Constraints as Assert;
/**
@MongoDB\Document
@MongoDB\Document(collection="article")
/
class article
{
    /*
    @MongoDB\Id(strategy="AUTO") */ 
    private $id;
    /**
    @MongoDB\ReferenceOne(targetDocument="user", inversedBy="articles") */
     private $user;
    /**
     */ 
    public function setUser(userProfile $user) 
    { 
        $this->user = $user;
        return $this; 
     }
    /**
     */ 
    public function getUser() {
        return $this->user; 
    }
}有谁能帮我弄到用户文章的列表吗?
谢谢
发布于 2017-07-17 22:07:07
由annotation管理的每个类都需要使用@ApiPlatform\Core\Annotation\ApiResource注释(或在YAML或XML中等效的注释)进行标记。
目前还没有本地的MongoDB支持(但这是正在进行中的工作)。
您仍然可以使用自定义的MongoDB添加数据提供者支持,但是如果您是API平台的新手,则应该尝试使用Doctrine并首先遵循官方教程:https://api-platform.com/docs/distribution/
https://stackoverflow.com/questions/36585375
复制相似问题