In magento 2, how to get value in core_config_data table.
Anyone know, show me step by step.Thanks!
In magento 2, how to get value in core_config_data table.
Anyone know, show me step by step.Thanks!
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);
you need to inject the an instance of \Magento\Framework\App\Config\ScopeConfigInterface in your block.
$protected $scopeConfig;
protected $storeManager;
public function __construct(
....
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Store\Model\StoreManagerInterface $storeManager,
....
) {
...
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
....
}
Then create the method getStoreName()
public function getStoreName()
{
return $this->scopeConfig->getValue(
'general/store_information/name',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->storeManager->getStore()->getStoreId()
);
}
and call in your template echo $this->getStoreName()
You can use \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, In your constructor argument and create an Object $this->scopeConfig = $scopeConfig;
Now, you can get config value as below:
$this->_scopeConfig->getValue('path of config', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
For more details, check these:
http://magehelper.blogspot.in/2015/06/get-system-config-values-in-magento-2.html https://maxyek.wordpress.com/2015/04/03/building-magento-2-extension-extendedconfig/