Shopware 6 : detail: "\"CustomTest\Controller\BackendController\" 没有容器集,你是不是忘了将其定义为服务订阅者?"

Shopware 6 : detail: "\"CustomTest\\Controller\\BackendController\" has no container set, did you forget to define it as a service subscriber?"

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

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

file: BackendController.php 有一个 below-route 作用域。


/**
     * @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);
        });
    }

当您在 src/Resources/config/services.xml 中注册您的控制器时,您必须调用方法 setContainer。参见 Shopware documentation。例如:

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