shopware - 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);
});
}
解决方案
当您在其中注册控制器时,src/Resources/config/services.xml
您必须调用方法setContainer
。请参阅Shopware 文档。例如:
<service id="YourNamespace\BackendController" public="true">
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
</service>
推荐阅读
- java - 获取USB 3.0设备盘符(Windows下Java)
- node.js - 如何使用 rust 像 nodejs 一样获取`__dirname`
- qt - 如何将 QString 作为 shared_ptr 传递
到 C++? - python - 如何使用 Python 的 PyPDF2 库从 PDF 文件中删除水印
- next.js - react-intl 与服务器端渲染
- ios - 在 App Store 中提交应用程序时,如何在基于 Mobile OTP 的登录时提供凭据?
- css - 像 SVG 一样添加右边框
元素 - shopify - 您可以将 shortID 从 SKU 更改为变体 ID 吗?(Shopify 集成)
- redirect - 如何将带有语言的网址重定向到原始主页
- java - 安装错误 Eclipse:安装失败