Estou com o seguinte erro
App\Controller\SeasonsController::index(): Argument #1 ($series) must be of type App\Entity\Series, string given, called in C:\projetos\alura\controle_series_symfony\vendor\symfony\http-kernel\HttpKernel.php on line 163
sempre que eu passo a serie como parâmetro para alguma função
#[Route('/series/{series}/seasons', name: 'app_seasons')]
public function index(Series $series): Response
{
segue o meu mapeamento
<?php
namespace App\Entity;
use App\Repository\SeriesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: SeriesRepository::class)]
class Series
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\OneToMany(targetEntity: Season::class,
mappedBy: 'series',
orphanRemoval: true,
cascade: ['persist']
)]
private Collection $seasons;
public function __construct(#[ORM\Column(type:"string", length:255)]
#[Assert\NotBlank]
#[Assert\Length(min: 5)]
private string $name = '')
{
$this->seasons = new ArrayCollection();
}
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;
}
/**
* @return Collection<int, Season>
*/
public function getSeasons(): Collection
{
return $this->seasons;
}
public function addSeason(Season $season): static
{
if (!$this->seasons->contains($season)) {
$this->seasons->add($season);
$season->setSeries($this);
}
return $this;
}
public function removeSeason(Season $season): static
{
if ($this->seasons->removeElement($season)) {
// set the owning side to null (unless already changed)
if ($season->getSeries() === $this) {
$season->setSeries(null);
}
}
return $this;
}
}
segue uma classe de exemplo
<?php
namespace App\Controller;
use App\Entity\Series;
use App\Repository\SeasonRepository;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Cache\CacheItemInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Cache\CacheInterface;
class SeasonsController extends AbstractController
{
private $seasonRepository;
public function __construct(private CacheInterface $cache, private SeasonRepository $repository)
{
}
#[Route('/series/{series}/seasons', name: 'app_seasons')]
public function index(Series $series): Response
{
/* $seasons = $this->cache->get("series_{$seriesId}_seasons",
function(CacheItemInterface $item){
$item->expiresAfter(new \DateInterval('PT10S'));
});
dd($seasons);
$seasons = $this->repository->findBy([
'series' => $seriesId
]);
return $this->render('seasons/index.html.twig', [
'seasons' => $seasons,
]);*/
return new Response('');
}
/*public function index(int $seriesId): Response
{
$seasons = $this->cache->get("series_{$seriesId}_seasons",
function(CacheItemInterface $item){
$item->expiresAfter(new \DateInterval('PT10S'));
});
dd($seasons);
$seasons = $this->repository->findBy([
'series' => $seriesId
]);
return $this->render('seasons/index.html.twig', [
'seasons' => $seasons,
]);
}*/
}
aparentemente não encontra essa entidade