首页 > 解决方案 > Shopware 6 : detail: "\"CustomTest\\Controller\\BackendController\" 没有设置容器,您是否忘记将其定义为服务订阅者?

问题描述

尝试将一些控制器添加到 Shopware 6 管理中,但在调查控制台时遇到 500 错误。

BackendController延伸到Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

file: BackendController.php有一个低于路线的范围。


/**
     * @RouteScope(scopes={"api"})
     * @Route("/api/_action/customtest/test", name="api.action.customtest.testConnection", methods={"GET"})
     *
     * @param Request $request
     * @param Context $context
     *
     * @return JsonResponse
     */
    public function getUserConnectionStatus(Request $request, Context $context): JsonResponse
    {
         
            $response = [
                'success' => true,
                'connected' => false,
                'link' => ''
                )
            ];        

        return new JsonResponse($response);
    }

file: connection-service-estatus.js


getConnectionSettingsStatus() {
        const apiRoute = `/_action/${this.getApiBasePath()}/test`;       
        return this.httpClient.get(
            apiRoute,
            {
                headers: this.getBasicHeaders()
            }
        ).then((response) => {
            return ApiService.handleResponse(response);
        });
    }

标签: shopware

解决方案


当您在其中注册控制器时,src/Resources/config/services.xml您必须调用方法setContainer。请参阅Shopware 文档。例如:

<service id="YourNamespace\BackendController" public="true">
    <call method="setContainer">
        <argument type="service" id="service_container"/>
    </call>
</service>

推荐阅读