magento2将表单保存到core_config_data

我使用的是magento2。 我有几个“ui_components”字段的表单,让我们说: field1 </ code>, field2 </ code>, field3 </ code>和保存</ code>按钮\ n如何将输入到所有字段的值保存到core_config_data?</ p>

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

  / ** 

  • @var \ Magento \ Framework \ App \ Config \ Storage \ WriterInterface
  • / nprotected $ configWriter; \ n / **
  • @param \ Magento \ Framework \ App \ Config \ Storage \ WriterInterface $ configWriter
  • /
    public function __construct(
    ....
    \ Magento \ Framework \ App \ Config \ Storage \ WriterInterface $ configWriter
    .....

    {
    $ this-&gt; configWriter = $ configWriter;
    }
    </ code> </ pre>

    < p>和调用方法:</ p>

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

    我知道每个字段都有 它自己的fieldID,但如何使用它来从中获取数据?</ p>

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

    < p>谢谢</ p>
    </ div>

展开原文

原文

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 Magento\Framework\App\Config\ScopeConfigInterface;

/**
 *  @var \Magento\Framework\App\Config\Storage\WriterInterface
 */
protected $configWriter;

/**
 *
 * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
 */
public function __construct(
    ....
    \Magento\Framework\App\Config\Storage\WriterInterface $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个回答



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

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

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

展开原文

dppi5167
dppi5167 感谢您对saveConfig的回答,但是如何从我的表单字段中获取值?
大约 2 年之前 回复



您可以在控制器类中发布值并保存到core_config_data表中。</ p>
</ div>

展开原文

原文

You can post your values in the controller class and save into core_config_data table.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问