Create Configration :
Create file inside etc/adminhtml/system.xml.
Get system config value in Magento2:
Create file inside etc/adminhtml/system.xml.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="tabid" translate="label" sortOrder="600">
<label>TabLabel</label>
</tab>
<section id="subtab_id" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sub Tab Name</label>
<tab>Sub Tab Name</tab>
<resource>NaeSpace_ModuleName::config</resource>
<group id="fieldName" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Setting</label>
<field id="fieldPath" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Text Field Name</label>
</field>
</group>
</section>
</system>
</config>
Value will store in core_config_data table.in path column it will be tabid/fieldName/fieldPath.And value column store saved value .
Get system config value in Magento2:
protected $_scopeConfig;
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) {
$this->_scopeConfig = $scopeConfig;
}
public function methodName()
{
$configValue = $this->_scopeConfig->getValue('tabid/fieldName/fieldPath', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
First argument is the value which we need from system configuration and the Second argument is the Store scope.
Comments
Post a Comment