In /var/www/html/magento2/app/code/Custommodule/ReviewRating/Block/HomehorizontalWidget.php

   <?php
namespace Custommodule\ReviewRating\Block;

class HomehorizontalWidget extends \Magento\Framework\View\Element\Template
{

protected $_helper;

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = [],
    \Custommodule\ReviewRating\Helper\Data $helper
) {
    parent::__construct($context, $data);

    $this->_helper = $helper;
}


    public function getEnable(){
        return $this->_helper->getEnable();
    }

}

In /var/www/html/magento2/app/code/Custommodule/ReviewRating/view/frontend/templates/homehorizontalwidget.phtml

<?php  echo $block->getEnable(); ?>

In /var/www/html/magento2/app/code/Custommodule/ReviewRating/Helper/Data.php

<?php 
namespace Custommodule_ReviewRating\ReviewRating\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper { 

    /** * @var \Magento\Framework\App\Config\ScopeConfigInterfac 
        */ 
    protected $_scopeConfig; 
    CONST ENABLE = 'reviewrating/general/enable_module'; 


    public function __construct( \Magento\Framework\App\Helper\Context $context, 
            \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig ) {

             parent::__construct($context); $this->_scopeConfig = $scopeConfig;
    }

    public function getEnable(){
        return $this->_scopeConfig->getValue(self::ENABLE);
    }


}

In /var/www/html/magento2/app/code/Custommodule/ReviewRating/etc/adminhtml/system.xml

system configuration labels created.

Error : 3 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid block type: Custommodule\ReviewRating\Block\HomehorizontalWidget Exception #1 (ReflectionException): Class Custommodule\ReviewRating\Helper\Data does not exist Exception #2 (ReflectionException): Class Custommodule\ReviewRating\Helper\Data does not exist

I followed this article how-to-create-a-magento-2-extension

UPDATE:: Issue resolved i have to change the namespace in In /var/www/html/magento2/app/code/Custommodule/ReviewRating/Helper/Data.php as suggested @Rakesh Jesadiya

up vote 1 down vote accepted

You just redeclare Custommodule_ReviewRating in your path instead of just one,

   <?php 
    namespace Custommodule\ReviewRating\Helper;

    class Data extends \Magento\Framework\App\Helper\AbstractHelper { 

        /** * @var \Magento\Framework\App\Config\ScopeConfigInterfac 
            */ 
        protected $_scopeConfig; 
        CONST ENABLE = 'reviewrating/general/enable_module'; 


        public function __construct( \Magento\Framework\App\Helper\Context $contex

t, 
            \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig ) {

             parent::__construct($context); $this->_scopeConfig = $scopeConfig;
    }

    public function getEnable(){
        return $this->_scopeConfig->getValue(self::ENABLE);
    }


}
  • 1
    var/www/html/magento2/app/code/Custommodule/ReviewRating/Helper/Data.php I changed the class name as ` namespace Custommodule\ReviewRating\Helper;` now its working fine. Thnak You – inrsaurabh Dec 16 '17 at 6:59

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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