Question

Magento 1.x use Mage::getStoreConfig('sections/groups/fields') get data on core_config_data table.

How to Magento2 get value from core_config_data table ?

Was it helpful?

Solution

We need to call the default method available.

Just Use \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, In your constructor argument and set the class property: $this->scopeConfig = $scopeConfig;

Now to Get the configuration value just use

$this->scopeConfig->getValue('dev/debug/template_hints', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

I have get the answer from this link and refer this

OTHER TIPS

Create a function for getting configuration values in your custom module's helper.

public function getConfig($config_path)
{
    return $this->scopeConfig->getValue(
            $config_path,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
            );
}

and call anywhere you want for example in test.phtml

$moduleStatus = $this->helper('Customvendorname\Custommodulename\Helper\Data')->getConfig('sectionid/groupid/fieldid');

In block and helper call like this:

 $this->_objectManager->create('Customvendorname\Custommodulename\Helper\Data')->getConfig('sectionid/groupid/fieldid');

I have used the following method to retrieve the variables,

if (empty($this->_data['welcome'])) {
    $this->_data['welcome'] = $this->_scopeConfig->getValue(
        'design/header/welcome',
        \Magento\Store\Model\ScopeInterface::SCOPE_STORE
    );
}

return $this->_data['welcome'];
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top