I have a module and I am trying to get my module config data ( from system.xml ) within my module controller. It works when I get it in a template file but not when I try to access it in the controler I get this error
Fatal error: Call to undefined method Modzinc\Productpdf\Controller\Index\Index\Interceptor::helper() in ..... public_html/modzinc/app/code/Modzinc/Productpdf/Controller/Index/Index.php on line 18
Here is my controller file located at Modzinc/Productpdf/Controller/Index.php
<?php
namespace Modzinc\Productpdf\Controller\Index;
use FPDF;
use Modzinc\Productpdf\Helper\Data;
use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\ResultFactory;
class Index extends Action
{
public function execute()
{
### Settings from Mod Config
$topTel = $this->helper('Modzinc\Productpdf\Helper\Data')->getConfig('dynamicpdf/general/topTel');
$pdfFont = 'Arial';
$product_id=$_GET['id'];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);
$pdf=new FPDF();
$pdf->AliasNbPages();
$pdf->SetTitle($product->getName());
$pdf->AddPage();
$pdf->SetFont($pdfFont,'',12);
$pdf->Cell(80);
$pdf->Cell(210,0,$topTel,1,2,'C');
$pdf->Output();
}
}
And my helper file contains the following
<?php
namespace Modzinc\Productpdf\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
);
}
}
Everything works fine apart from when I try to use the helper to get the config value.
Can someone tell me what I am doing wrong please, I am rather new to Magento 2