I'm trying to get value from the core_config_data
table but when I follow various guides on the internet or previous topics here, it doesn't work..
Disclaimer: I'm new to PHP and Magento in general so I'm not completely sure what I'm doing..
The class is:
class Db
{
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
{
$this->_scopeConfig = $scopeConfig;
}
public function getApiKey()
{
$getApiKey = $this->_scopeConfig->getValue('vendor_module/general/ApiKey',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
return $getApiKey;
}
}
When I try to instantiate the class by calling $new = Db(); $new->getApiKey;
it returns the below error:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function vendor\module\src\Model\Db::__construct(), 0 passed in /xxxxx/src/Model/Db.php on line 23 and exactly 1 expected in /xxxxx/src/Model/Db.php on line 9
I have tried to re-run setup:di:compile
cleared cache folders, removed contents of magento/generated
(I don't have var/generation
in magento 2.2.0..) and still nothing.
Links I'm aware of: How to get value from `core_config_data` table in Magento 2
https://maxyek.wordpress.com/2015/04/03/building-magento-2-extension-extendedconfig/
http://magehelper.blogspot.co.uk/2015/06/get-system-config-values-in-magento-2.html
Any help will be much appreciated.