洋红色2 将表单保存到core_config_data



我正在使用 magento2。我有很少的"ui_components"字段的表单,比如说:field1field2field3Save按钮 如何将输入到所有字段的值保存到core_config_data?

关于core_config_data我知道我必须使用它来保存数据: 使用 Magento\Framework\App\Config\ScopeConfigInterface;

/**
*  @var MagentoFrameworkAppConfigStorageWriterInterface
*/
protected $configWriter;
/**
*
* @param MagentoFrameworkAppConfigStorageWriterInterface $configWriter
*/
public function __construct(
....
MagentoFrameworkAppConfigStorageWriterInterface $configWriter
.....
)
{
$this->configWriter = $configWriter;
}

对于调用方法:

$this->configWriter->save('my/path/whatever',  $value, $scope =ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);

我知道每个字段都有自己的字段 ID,但如何使用它从中获取数据?

以及如何将每个字段值保存到单独的核心配置行中?

谢谢

有相同的 saveConfig 方法: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Model/ResourceModel/Config.php#L26-L61

来自核心的使用示例:https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Payment/Observer/UpdateOrderStatusForPaymentMethodsObserver.php#L59-L64

源: https://magento.stackexchange.com/questions/92917/magento-2-programmatically-add-a-value-to-core-config-data

您可以将值发布到控制器类中并保存到core_config_data表中。

最新更新