I need to create a simple Shopware 6 Controller... My problem is that even by copying the exact code from the docs/tutorial, I am not able to get the controller to work...
My error:
Call to a member function hasScope() on array
The code of my controller:
<?php declare(strict_types=1);
namespace ArvKalbacherCustomization\Storefront\Controller;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
class ExampleController extends StorefrontController
{
/**
* @Route("/example", name="frontend.example.example", methods={"GET"})
*/
public function showExample(): Response
{
return $this->renderStorefront('@ArvKalbacherCustomization/storefront/page/example.html.twig', [
'example' => 'Hello world'
]);
}
}
This is my service.xml
<service id="ArvKalbacherCustomization\Storefront\Controller\ExampleController" public="true">
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
</service>
Here are my routes:
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="../../Storefront/Controller/**/*Controller.php" type="annotation"/>
</routes>
I really hopy anyone can help me :)
CodePudding user response:
I assume this must be version related as on the current trunk this works fine. This commit from 6.4.11.0
onwards introduced the _routeScope
default as a replacement for the deprecated @RouteScope
annotation.
Also see the documentation.