- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Charlie Simmons
Developer
Payment Processing, Payroll Solutions and Rewards
One Heartland Way
Jeffersonville, IN 47130
HeartlandPaymentSystems.com facebook.com
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: getConfigData
How to get a modules's backend configuration option value? https://mage2.pro/t/758
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: getConfigData
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');
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: getConfigData
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
- one answer that probably should in theory have worked
- one perhaps exhaustive answer to something i wasn't really asking.
The surprise here!!!
- Your answer which was exactly what i was hoping for. a couple targeted lines of code that was complete and addressed my specific question
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
Charlie Simmons
Developer
Payment Processing, Payroll Solutions and Rewards
One Heartland Way
Jeffersonville, IN 47130
HeartlandPaymentSystems.com facebook.com