Reputation: 59
I am working on a symfony 5.3 web dev project, everything works well with symfony until I use apiplatform 2.6 for the api.
When I try to access the api entrypoint in the browser http://127.0.0.1:8000/api/ I have the ReflectionException Class App\Entity\collection does not exist although the same link works well in postman (See output in the attached image) and I don't have any collection entity in my project. Does anyone have any idea how to fix this?
All my api calls work in postman, but not in the browser. Thanks in advance for your comments.
Code example for season class
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\SeasonRepository;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ORM\Entity(repositoryClass=SeasonRepository::class)
* @ApiResource(
* normalizationContext={"groups"={"season:read"}},
* denormalizationContext={"groups"={"season:write"}}
* )
*/
class Season
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups("season:read")
* @SerializedName("seasonDbId")
*/
private $id;
/**
* @ORM\Column(type="text")
* @Groups("season:read")
* @SerializedName("seasonName")
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
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;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function __toString()
{
return (string) $this->name;
}
}
Maybe the problem is there. Collection from use Doctrine\Common\Collections\Collection; is the interface for App\Entity\Collection, but apiplatform seems not to be able to connect with it. I decided to try for testing only creating myself a Collection class in App\Enity\ to see the behavior. I have just created an empty class named Collection in \App\Entity, it worked, when I refreshed the page, same error appears. This is crazy.
Upvotes: 1
Views: 447
Reputation: 41
Have you forgot to import Collection with namespace in an Entity ?
If you use a Collection object but with no namespace, the default namespace is the current namespace. If your collection are call in App\Entity the default collection class became App\Entity\Collection.
Another probleme i could see is App\Entity\collection should be App\Entity\Collection with uppercase first char.
Are you using doctrine collection ? plateform api collection ?
Upvotes: 1