0

I'm trying to get registry value in my block. Here's how block looks like,

<?php
namespace Vendor\Dunning\Block\Adminhtml\Dunning\Edit\Tab;

class PartPayments extends \Magento\Backend\Block\Template
{
    protected $_template = 'Vendor_Dunning::installments.phtml';

    public function __construct(
            \Magento\Framework\Registry $registry
    ) {
        $this->registry     = $registry;
    }
}

Template is getting rendered but If I create constructor then it gives me error like below which looks dangerous to debug.

Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Call to a member function dispatch() on null in /opt/lampp/htdocs/magento2/vendor/magento/module-ui/Component/Wrapper/UiComponent.php on line 0

Please help.

2 Answers 2

1

It seems like error occurred from other code. Still, you can create registry like :

<?php
namespace Vendor\Dunning\Block\Adminhtml\Dunning\Edit\Tab;

class PartPayments extends \Magento\Backend\Block\Template
{
    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry
     */
    protected $_coreRegistry = null;

    protected $_template = 'Vendor_Dunning::installments.phtml';

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }
}

Reference file : Magento\Cms\Block\Adminhtml\Wysiwyg\Images/Tree.php

1

I'm using Registry in my block from getting the function of the Registry which I created in helper class n its works perfectly for me... you can give a try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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