Hallo,
ich bekomme mit Shopware 6.5 in einem Plugin bei einer Controller Action jetzt …
Class MyVendor\Controller\Storefront\MyExampleController does not have twig injected. Add to your service definition a method call to setTwig with the twig instance
Die Fehlermeldung wird dadurch geworfen:
return $this->renderStorefront(‚storefront/page/product-detail/my_example/product-example-form.html.twig‘, [
‚productId‘ => $productId,
‚saveSuccess‘ => 1
]);
Die Annotation Route:
@Route(„/my_vendor/saveexample/{productId}“, name=„frontend.detail.save-example“, methods={„POST“}, defaults={„XmlHttpRequest“=true})
Unter 6.4 ging noch alles einwandfrei. Was muss unter 6.5 geändert werden, damit im Controller das Twig-Template wieder gerendert wird.
Gruss
Du musst in deiner services.xml einen call bei deinem Controller-Service hinzufügen:
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
<call method="setTwig">
<argument type="service" id="twig"/>
</call>
Danke, das wars tatsächlich, war mit 6.4 noch nicht nötig, da war der Service scheinbar automatisch verfügbar
Das sollte hier in die Dhopware 6.5 (latest) Dokumentation aufgenommen werden.
Dokumentation:
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="Swag\BasicExample\Storefront\Controller\ExampleController" public="true">
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
</service>
</services>
</container>
Solle sein:
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="Swag\BasicExample\Storefront\Controller\ExampleController" public="true">
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
<call method="setTwig">
<argument type="service" id="twig"/>
</call>
</service>
</services>
</container>