首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >API平台:没有为类型为“AppBundle\Document\制品”的对象找到任何资源

API平台:没有为类型为“AppBundle\Document\制品”的对象找到任何资源
EN

Stack Overflow用户
提问于 2016-04-12 22:40:37
回答 1查看 894关注 0票数 1

我正在使用symfony2 API平台从我的mongodb数据库中生成api,但是我得到了以下错误:hydra:description:“找不到”AppBundle\Document\ “类型对象的资源

我有两个mongo文档用户和一个文章,每个用户都有多个文章,所以我试图列出所有用户的所有文章标题,这样我就可以得到如下内容:

代码语言:javascript
运行
复制
{
@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']
}

这是我的代码:

用户文档

代码语言:javascript
运行
复制
<?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;
    }
}

文章文档

代码语言:javascript
运行
复制
<?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; 
    }
}

有谁能帮我弄到用户文章的列表吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-07-17 22:07:07

由annotation管理的每个类都需要使用@ApiPlatform\Core\Annotation\ApiResource注释(或在YAML或XML中等效的注释)进行标记。

目前还没有本地的MongoDB支持(但这是正在进行中的工作)。

您仍然可以使用自定义的MongoDB添加数据提供者支持,但是如果您是API平台的新手,则应该尝试使用Doctrine并首先遵循官方教程:https://api-platform.com/docs/distribution/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36585375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档