6

This question already has an answer here:

In magento 2, how to get value in core_config_data table.

Anyone know, show me step by step.Thanks!

marked as duplicate by 7ochem, Murtuza Zabuawala, Raphael at Digital Pianism, Rajeev K Tomy, Amit Bera Nov 18 '16 at 16:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

8

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);
  • $this->scopeConfig->getValue() must be in multi line because as Magento2 EcgM2 standard show error "Line exceeds 120 characters". – Prince Patel May 20 '17 at 13:36
5

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()

1

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/

Not the answer you're looking for? Browse other questions tagged or ask your own question.