I am using magento2. I have form with few “ui_components” fields, lets say: field1
, field2
,field3
and Save
button
How can I save values that was enter to all fields to core_config_data?
regarding core_config_data I know that I have to use this, to save data there:
use MagentoFrameworkAppConfigScopeConfigInterface;
/**
* @var MagentoFrameworkAppConfigStorageWriterInterface
*/
protected $configWriter;
/**
*
* @param MagentoFrameworkAppConfigStorageWriterInterface $configWriter
*/
public function __construct(
....
MagentoFrameworkAppConfigStorageWriterInterface $configWriter
.....
)
{
$this->configWriter = $configWriter;
}
and for calling method :
$this->configWriter->save('my/path/whatever', $value, $scope =ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);
I know each of the fields have its own fieldID, but how to use it to get data from it?
and how to save each of the fields values into separate core config row?
Thanks
2
Answers
There is the same saveConfig method: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Model/ResourceModel/Config.php#L26-L61
A usage example from the core: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Payment/Observer/UpdateOrderStatusForPaymentMethodsObserver.php#L59-L64
Source :
https://magento.stackexchange.com/questions/92917/magento-2-programmatically-add-a-value-to-core-config-data
You can post your values in the controller class and save into core_config_data table.