有我的主控制器:
<?php
namespace App\Controller;
use App\Entity\ShopCart;
use App\Entity\ShopItem;
use App\Repository\ShopItemRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Config\Framework\SessionConfig;
use Symfony\Component\HttpFoundation\RequestStack;
class MainController extends AbstractController
{
private SessionInterface $session;
/**
* @param SessionInterface $session
*/
public function __construct(SessionInterface $session)
{
$this->session = $session;
$this->session->start();
}
public function debug($data)
{
echo '<pre>' . print_r($data) . '</pre>';
}
#[Route('shop/list', name: 'List')]
public function shopList(EntityManagerInterface $entityManager, ShopItemRepository $shopItemRepository): Response
{
$result = $shopItemRepository->findAll();
return $this->render('shop-list.html.twig', [
'shoes' => …Run Code Online (Sandbox Code Playgroud)