Php 装饰Shopware6 api控制器以将pluginreader数据保存到实体
安装插件并编辑配置中的可用字段后,我想将这些字段保存到我的实体中 因此,我创建了Config类,以便从插件配置中获取字段getter,如下所示:Php 装饰Shopware6 api控制器以将pluginreader数据保存到实体,php,shopware,Php,Shopware,安装插件并编辑配置中的可用字段后,我想将这些字段保存到我的实体中 因此,我创建了Config类,以便从插件配置中获取字段getter,如下所示: class Config { public const SYSTEM_CONFIG_DOMAIN = 'myEntity.config.'; /** @var SystemConfigService $systemConfigService */ protected static $systemConfigService;
class Config
{
public const SYSTEM_CONFIG_DOMAIN = 'myEntity.config.';
/** @var SystemConfigService $systemConfigService */
protected static $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
self::$systemConfigService = $systemConfigService;
}
}
public static function message(): string
{
return (string)self::$systemConfigService->get(self::SYSTEM_CONFIG_DOMAIN . 'message');
}
我在平台上发现了这样一个控制器:
/**
* @Route("/api/v{version}/_action/system-config/batch", name="api.action.core.save.system-config.batch", methods={"POST"})
*/
public function batchSaveConfiguration(Request $request): JsonResponse
{
foreach ($request->request->all() as $salesChannelId => $kvs) {
if ($salesChannelId === 'null') {
$salesChannelId = null;
}
$this->saveKeyValues($salesChannelId, $kvs);
}
//save to my entity here
return new JsonResponse([$request->request->all()]);
}
在这个控制器中,我想将我的消息从PluginFig添加到我的实体中。
这是个好主意吗?我该如何感谢它?因为我刚刚学习sw6,我能要求更多的代码吗?如果你只想在插件配置中添加数据,你应该使用配置安装程序而不是控制器