我使用 Api 平臺和 Symfony (5.4) php 7.2.5
我自己創建了一個物體,我只是在 /src/Entity 中添加了一個檔案,但它不起作用。
我重繪 ,我清除了快取,我添加了@ApiResource ...但是物體在 API 平臺的檔案頁面中不可見。
你知道錯誤在哪里嗎?謝謝 !
這是我用于新物體的代碼:
// api/src/Entity/Review.php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
/** A review of a book. */
/**
* @ApiResource()
*/
class Review
{
/** The id of this review. */
private ?int $id = null;
/** The rating of this review (between 0 and 5). */
public int $rating = 0;
/** The body of the review. */
public string $body = '';
/** The author of the review. */
public string $author = '';
/** The date of publication of this review.*/
public ?\DateTimeInterface $publicationDate = null;
/** The book this review is about. */
public ?Book $book = null;
public function getId(): ?int
{
return $this->id;
}
}
uj5u.com熱心網友回復:
我認為您應該洗掉您的物體并使用 cmd 重新制作它:
php bin/console make:entity
這將在物體檔案夾中創建一個 Rewiew.php 檔案,其中包含 getter 和 setter 以及正確的注釋示例:
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
和存盤庫檔案等。不要忘記使用:
php bin/console make:遷移
和:
php bin/控制臺原則:遷移:遷移
用于更新您的資料庫。并且不要忘記使用 apiplatform 注釋。我認為實際上由于缺少資訊,捆綁包無法知道如何使用您的物體
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/460451.html
標籤:php 交响乐 实体 api-platform.com
