i want to call
getConfigData('some key from my payment config')
I want to do this in a controller file
I cannot for the life of me figure out what classes to instantiate to get to it
Solved! Go to Solution.
1) create the helper Helper/Data.php for example
<?php namespace [Vendor]\[ModuleName]\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { public function getConfig($config_path) { return $this->scopeConfig->getValue( $config_path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } }
2) then in the controller you can use
$config = $this->_objectManager->get('[Vendor]\[ModuleName]\Helper\Data')->getConfig('[ConfigPath]');
It may be there is easiest way but it works fine for me
1) create the helper Helper/Data.php for example
<?php namespace [Vendor]\[ModuleName]\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { public function getConfig($config_path) { return $this->scopeConfig->getValue( $config_path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } }
2) then in the controller you can use
$config = $this->_objectManager->get('[Vendor]\[ModuleName]\Helper\Data')->getConfig('[ConfigPath]');
It may be there is easiest way but it works fine for me
How to get a modules's backend configuration option value? https://mage2.pro/t/758
Hi,
Below are the steps to call getConfigData value.
1. Create Helper/Data.php file
namespace [Vendor]\[ModuleName]\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { public function getConfig($config_path) { return $this->scopeConfig->getValue( $config_path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } }
2. Using the following function you can call the store config value on front end.
echo $this->getConfig('section_id/group_id/field_id');
AJAX ZOOM
You sir are a refreshing change. You provided a Concise even if not exhaustive answer. I was asking what should have been a simple question and as usual to what i have seen on this board i got
The surprise here!!!
I am unsure why every simple thing a dev could want to do seems to get answers that require 5 gaggillion different files and millions of lines of code. I hope you continue to demonstrate how to answer forum posts. You see, since you gave me a concise answer. I am able to build upon it in a constructive way. You also succeeded in the "teach a man to fish" philosophy