Tried every thing to send data but not work. In the index controller what can i use to send the data to template file.

public function execute()
    /** @var \Magento\Backend\Model\View\Result\Page $resultPage */

    $post = $this->getRequest()->getPostValue();
    $we =  $this->getRequest()->getParams();         

   // echo "<pre>";print_r($we);        
        $register_email= $we['ripple_email']; 
        include_once 'afclass.php';  
        // $curl_info = new afclass;
        $asset_id = Afclass::before_registration($register_email); 
        $value =225; 
        $block = $this->_view->getLayout()->createBlock('module\Block\Adminhtml\CustomBlock');






2 Answers 2


When you create your block with $block = $this->_view->getLayout()->createBlock('module\Block\Adminhtml\CustomBlock');, you can pass data to it using the 3rd argument to the createBlock function. For example:

$block = $this->_view->getLayout()->createBlock('module\Block\Adminhtml\CustomBlock', 'block name', ['data' => ['MyData' => 'value']]);

The data will then be accessible to your block through the $data array that is passed to it's constructor.

  • i got it simply change the createBlock('module\Block\Adminhtml\CustomBlock') by createBlock('blockname'); Jul 2, 2016 at 9:21

You could also use assign() function

$block = $this->_view->getLayout()->createBlock('module\Block\Adminhtml\CustomBlock');
    'bar' => 'foo'

so in custom template file you could use

<?php echo $bar; //output 'foo' ?>

The assign() function could be useful when you don't need to create block instance, for example because you have already block in layout and you retrieve it with

$block = $this->_view->getLayout()->getBlock('foobar');

Your Answer

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

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