Calling system config value

by Jurģis Toms Liepiņš   Last Updated January 12, 2018 12:09 PM

I am trying to get my system config values and so far compared to M1 it's been very frustrating.
I am following this tutorial.

Everything works fine, but as soon as I want to call the values with:

$this->scopeConfig->getValue('helloworld/general/enable', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

I get a

Notice: Undefined property:Mageplaza\HelloWorld\Controller\Index\Test\Interceptor::$scopeConfig
Tags : magento2


Answers 1


Define construct function for pass the object manager as DI.

Define below code in your file in construct function

protected $_scopeConfig;
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
    {
    $this->_scopeConfig = $scopeConfig;
    }

Now call config value with below code

$value = $this->_scopeConfig->getValue('helloworld/general/enable', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

run command php bin/magento setup:di:compile.

it should work now.

akgola
akgola
January 12, 2018 12:07 PM

Related Questions


Cart Price Rules having issues

Updated October 01, 2018 18:09 PM


Magento 2.2 Not Loading theme and blocks

Updated January 11, 2018 02:09 AM