api 平台

编程入门 行业动态 更新时间:2024-10-05 21:25:30
本文介绍了api 平台 - 无法为项目生成 IRI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我从 API 平台开始,我正在使用示例实体Foo":

I'm starting with API Platform and I'm using the example entity "Foo":

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;


/**
 * Foo
 *
 * @ORM\Table(name="foo")
 * @ApiResource
 * @ORM\Entity
 */
class Foo
{
    /**
     * @var string
     *
     * @ORM\Column(name="bar", type="string", length=255, nullable=false)
     */
    private $bar;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;


}

我成功地在仪表板中看到了新实体(见图):

I succesfully see the new Entity in dashboard (See image):

API 平台仪表板

当我尝试获取所有 Foo 集合时出现以下错误:

And I had the following error when I try to get all Foo collection:

curl -X GET "http://127.0.0.1:8000/foos" -H "accept: application/json"

    {
  "type": "https://tools.ietf/html/rfc2616#section-10",
  "title": "An error occurred",
  "detail": "Unable to generate an IRI for the item of type \"AppBundle\\Entity\\Foo\"",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/home/xxxx/api/vendor/api-platform/core/src/Bridge/Symfony/Routing/IriConverter.php",
      "line": 107,
      "args": []
    },

我尝试了不同的格式并检查了路线:

I tried different formats and check the the routes too:

 julian@js:~/xxxxx/api$ ./bin/console debug:router
 ------------------------------- -------- -------- ------ ----------------------------------- 
  Name                            Method   Scheme   Host   Path                               
 ------------------------------- -------- -------- ------ ----------------------------------- 
  _wdt                            ANY      ANY      ANY    /_wdt/{token}                      
  _profiler_home                  ANY      ANY      ANY    /_profiler/                        
  _profiler_search                ANY      ANY      ANY    /_profiler/search                  
  _profiler_search_bar            ANY      ANY      ANY    /_profiler/search_bar              
  _profiler_phpinfo               ANY      ANY      ANY    /_profiler/phpinfo                 
  _profiler_search_results        ANY      ANY      ANY    /_profiler/{token}/search/results  
  _profiler_open_file             ANY      ANY      ANY    /_profiler/open                    
  _profiler                       ANY      ANY      ANY    /_profiler/{token}                 
  _profiler_router                ANY      ANY      ANY    /_profiler/{token}/router          
  _profiler_exception             ANY      ANY      ANY    /_profiler/{token}/exception       
  _profiler_exception_css         ANY      ANY      ANY    /_profiler/{token}/exception.css   
  _twig_error_test                ANY      ANY      ANY    /_error/{code}.{_format}           
  api_entrypoint                  ANY      ANY      ANY    /{index}.{_format}                 
  api_doc                         ANY      ANY      ANY    /docs.{_format}                    
  api_jsonld_context              ANY      ANY      ANY    /contexts/{shortName}.{_format}            
  api_foos_get_collection         GET      ANY      ANY    /foos.{_format}                    
  api_foos_post_collection        POST     ANY      ANY    /foos.{_format}                    
  api_foos_get_item               GET      ANY      ANY    /foos/{id}.{_format}               
  api_foos_put_item               PUT      ANY      ANY    /foos/{id}.{_format}               
  api_foos_delete_item            DELETE   ANY      ANY    /foos/{id}.{_format}               

 ------------------------------- -------- -------- ------ ----------------------------------- 

我的服务器可能需要一些特殊的库吗?我做错了什么?

It's possible what I need some special library in my server? What I'm doing wrong?

提前致谢!

推荐答案

你的 id 缺少一个 getter

You're missing a getter for your id

public function getId()
{
    return $this->id;
}

这篇关于api 平台 - 无法为项目生成 IRI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 02:53:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/928327.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:平台   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!