Hi,
ich möchte für meine kleine Shop-Extension gerne einen SessionBag registrieren.
Ich habe etwas von Contao adaptiert und eigentlich sollte das gehen. Tut es aber nicht.
Contao registriert seine SessionBags so:
Ich wollte mich nun an Contao dran hängen und habe das programmiert:Code:contao.session.factory:
class: Contao\CoreBundle\Session\SessionFactory
decorates: session.factory
arguments:
- '@contao.session.factory.inner'
- '@contao.session.contao_backend'
- '@contao.session.contao_frontend'
Die Konsole wirfst keinen Fehler:Code:Bits\MmShopBundle\Session\CartSessionBag:
public: true
Bits\MmShopBundle\Session\SessionFactory:
decorates: contao.session.factory
arguments:
- '@contao.session.factory.inner'
- '@Bits\MmShopBundle\Session\CartSessionBag'
Trotzdem bekomme ich im Frontend, die Nachricht das meine SessionBag nicht registriert ist.Code:Information for Service "Bits\MmShopBundle\Session\SessionFactory"
==================================================================
---------------- ---------------------------------------------------------------------------------------------------------
Option Value
---------------- ---------------------------------------------------------------------------------------------------------
Service ID Bits\MmShopBundle\Session\SessionFactory
Class Bits\MmShopBundle\Session\SessionFactory
Tags container.decorator (id: contao.session.factory, inner: Bits\MmShopBundle\Session\SessionFactory.inner)
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired yes
Autoconfigured yes
Usages contao.session.factory
ContaoCommunityAlliance\DcGeneral\SymfonyBridge\SessionFactory.inner
ContaoCommunityAlliance\DcGeneral\SymfonyBridge\SessionFactory
Vielleicht ist es noch notwendig zu erwähnen das ich einen eigenen Controller nutze?
Das Framework wird ja initialisiert.PHP-Code:
<?php
namespace Bits\MmShopBundle\Controller;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Controller\AbstractController;
use Contao\PageModel;
use Contao\PageRegular;
use Contao\System;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Bits\MmShopBundle\Service\ResourceResolver;
use Doctrine\DBAL\Connection;
#[Route(defaults: ['_scope' => 'frontend'])]
class ProductDetailController extends AbstractController
{
public function __construct(
private Connection $db,
private ResourceResolver $resourceResolver,
private readonly ContaoFramework $framework
) {
$this->resourceResolver = $resourceResolver;
}
public function __invoke(Request $request, string $alias, string $category): Response
{
$this->framework->initialize();
if (!$this->resourceResolver->isProduct($category,$alias) || !$this->resourceResolver->isProductCategory($category)) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
global $objPage;
$objPage = PageModel::findPublishedById('195');
$request->attributes->set('pageModel', $objPage);
if (!$objPage) {
throw new \RuntimeException('Detailseite nicht gefunden.');
}
// Übergib die Seite an Contao's regulären Renderer
$controller = new PageRegular();
return $controller->getResponse($objPage, false);
}
}
Woran kann das liegen?:eek: