You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopware 6创建店面控制器失败:Call to a member function hasScope() on array

Shopware 6控制器报错:Call to a member function hasScope() on array 求助

我按照官方文档/教程的代码创建了一个简单的Shopware 6控制器,但运行时始终报错:

Call to a member function hasScope() on array

附带堆栈追踪截图。以下是我的控制器代码、service.xml配置及路由配置,恳请协助排查问题:

控制器代码

<?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'
        ]);
    }
}

service.xml配置

<service id="ArvKalbacherCustomization\Storefront\Controller\ExampleController" public="true">
    <call method="setContainer">
        <argument type="service" id="service_container"/>
    </call>
</service>

路由配置

<?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>

内容的提问来源于stack exchange,提问作者Aaron Sommer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 03:06:40