Saya menggunakan kode ini di salah satu modul saya.
Ubah Custommodule menjadi NameSpace (Nama perusahaan Anda) ubah ReviewRating menjadi (Nama Modul Anda)
Di /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();
}
}
Di /var/www/html/magento2/app/code/Custommodule/ReviewRating/view/frontend/templates/homehorizontalwidget.phtml
<?php echo $block->getEnable(); ?>
Di /var/www/html/magento2/app/code/Custommodule/ReviewRating/Helper/Data.php
<?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 $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig ) {
parent::__construct($context); $this->_scopeConfig = $scopeConfig;
}
public function getEnable(){
return $this->_scopeConfig->getValue(self::ENABLE);
}
}
Di /var/www/html/magento2/app/code/Custommodule/ReviewRating/etc/adminhtml/system.xml
system configuration labels created here