cancel
Showing results for 
Search instead for 
Did you mean: 

getConfigData

SOLVED

getConfigData

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
4 REPLIES

Re: getConfigData

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

Checkout our Magento AJAX-ZOOM mouseover zoom + 360 spin extension

Re: getConfigData

How to get a modules's backend configuration option value? https://mage2.pro/t/758

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');

 

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 

  1. one answer that probably should in theory have worked
  2. one perhaps exhaustive answer to something i wasn't really asking.

The surprise here!!!

  1. 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