I'm trying to call my custom Helper class in Controller but when I call the function of my helper in Controller it gives me Fatal error: Uncaught Error: Call to undefined method Magento\Backend\Helper\Data::getSKUU()getSKUU() is my custom helper function and the code is calling the core helper class while I'm injecting my custom Helper class in the controller


namespace Vender\Module\Controller\Adminhtml\Index;

use Vender\Module\Helper\Email;
use Vender\Module\Helper\Data;
use Magento\Backend\App\Action;
use Magento\Framework\App\Action\Context;
class AcceptOffer extends \Magento\Backend\App\Action
    protected $_model;
    protected $helper;

    function __construct(
         \Vender\Module\Model\ResourceModel\MakeAnOffer\CollectionFactory $model,
        \Magento\Framework\App\Request\Http $request,
        Context $context,
        Email $email,
        \Vender\Module\Helper\Data $helper,
        \Vender\Module\Model\MakeAnOffer $mode
        $this->_model = $model;
        $this->request = $request;
        $this->_email = $email;
        $this->_helper= $helper;
        $this->_mode = $mode;

    public function execute()
        $id= $this->request->getParam('id');


        $dataa = $this->_model->create()->addFieldToFilter('makeanoffer_id',$id)->getData(); 
        // print_r($dataa);exit;
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
            try {
                // $this->_helper->setCoupon();
                $this->messageManager->addSuccessMessage('The Offer has been Accepted!');
                return $resultRedirect->setPath('*/*/index');

            } catch (\Exception $e) {

                // display error message
                // go back to edit form
                return $resultRedirect->setPath('*/*/index');

//Not colling my custom Helper Class

This $this->_helper= $helper; should be $this->helper= $helper; as you are declaring the $helper without '_'

  • ok so if I declare $helper** like **$_helper and after that I write $this->_helper= $_helper is it will work then??? – Asad Khan Apr 3 '19 at 9:05
  • I think so. should try first. – fmsthird Apr 3 '19 at 9:06
  • Its not working like that as well... it works on $this->helper= $helper; but its not making any sense for me can you please explain me??? like same as well I have the Email class as well in the helper but its works properly even I'm declaring the class like $this->_email = $email; – Asad Khan Apr 3 '19 at 9:15
  • yeah the same in my answer it should work. check again my answer. I think because helper is a reserve word for Magento core helper – fmsthird Apr 3 '19 at 9:17
  • Yeah Yeah... I'm just telling you that your code $this->helper= $helper; is working but the same $this->_helper= $_helper; is not working. – Asad Khan Apr 3 '19 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.