I have this error "argument "$session" of method "__construct()" references interface "Symfony\Component\HttpFoundation\Session\SessionInterface" but no such service exists. "
And i don't really know how to fix any idea ?
Cannot autowire service "App\Storage\CartSessionStorage": argument "$session" of method "__construct()" references interface "Symfony\Component\HttpFoundation\Session\SessionInterface" but no such service exists. Did you create a class that implements this interface?
This tutorial was written with Symfony 5 and it's not compatible with version 6 at this time. In Symfony 6, the Session service has been removed. To get the Session, you now need to inject the RequestStack service and use the new getSession() method.
You need to upgrade the CartSessionStorage like that :
namespaceApp\Storage;useApp\Entity\Order;useApp\Repository\OrderRepository;useSymfony\Component\HttpFoundation\RequestStack;/**
* Class CartSessionStorage
* @package App\Storage
*/classCartSessionStorage{/**
* @var RequestStack
*/private$requestStack;/**
* The cart repository.
*
* @var OrderRepository
*/private$cartRepository;/**
* @var string
*/constCART_KEY_NAME='cart_id';/**
* CartSessionStorage constructor.
*
* @param RequestStack $requestStack
* @param OrderRepository $cartRepository
*/publicfunction__construct(RequestStack$requestStack,OrderRepository$cartRepository){$this->requestStack=$requestStack;$this->cartRepository=$cartRepository;}/**
* Gets the cart in session.
*
* @return Order|null
*/publicfunctiongetCart():?Order{return$this->cartRepository->findOneBy(['id'=>$this->getCartId(),'status'=>Order::STATUS_CART]);}/**
* Sets the cart in session.
*
* @param Order $cart
*/publicfunctionsetCart(Order$cart):void{$this->requestStack->getSession()->set(self::CART_KEY_NAME,$cart->getId());}/**
* Returns the cart id.
*
* @return int|null
*/privatefunctiongetCartId():?int{return$this->requestStack->getSession()->get(self::CART_KEY_NAME);}}
I have this error "argument "$session" of method "__construct()" references interface "Symfony\Component\HttpFoundation\Session\SessionInterface" but no such service exists. "
And i don't really know how to fix any idea ?
Hello. Could you check if the session is enabled in the configuration file
config/packages/framework.yaml
? You should have :More details on symfony.com/doc/current/session.ht...
Done! but still this message
Cannot autowire service "App\Storage\CartSessionStorage": argument "$session" of method "__construct()" references interface "Symfony\Component\HttpFoundation\Session\SessionInterface" but no such service exists. Did you create a class that implements this interface?
my framework.yaml
What version of Symfony are you using?
Symfony 6.0
This tutorial was written with Symfony 5 and it's not compatible with version 6 at this time. In Symfony 6, the Session service has been removed. To get the Session, you now need to inject the RequestStack service and use the new getSession() method.
You need to upgrade the
CartSessionStorage
like that :It worked! It seems that everything is good now.
Thanks!
Try this
PHP bin/console req http