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 ?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityWe 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);
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');
$this->_objectManager->create(...)
should be avoided.
Jun 22, 2016 at 12:27
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'];
First you need to include the Magento\Store\Model\ScopeInterface
class in your constructor:
protected $_scopeConfig;
public function __construct(
...
\Magento\Store\Model\ScopeInterface $scopeInterface,
...
)
{
...
$this->_scopeConfig = $scopeInterface;
...
}
Then in your class' method you can call the following:
$this->scopeConfig->getValue('path/of/config', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
Most likely your class already has a Magento\Framework\App\Helper\Context
injected. You can get a ScopeConfig
from there:
$this->context->getScopeConfig()->getValue(
'sections/groups/fields',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
In template (phtml) files, I use in the following way:
$config = $block->getLayout()->createBlock(\Magento\Config\Block\System\Config\Form::class);
$configValue = $config->getConfigValue('web/secure/base_url');