A page is submitted with the Voucher Number to check if it is valid, and if it is, then it the user moves forward in the process. How can I pass this value to the phtml to use again? Preferably I would like to pass it back as part of the model.
public function execute()
{
// Get submitted voucher number
$voucherNumber = $_POST['voucher-number'];
// Validate the voucher number
if($this->_objectManager->create('Hidden\Hidden\Helper\VoucherHelper')->validate($voucherNumber)){
// Valid
// ******** NEED TO RETURN $voucherNumber here
return $this->resultPageFactory->create();
}
else {
// Invalid
return $this->_redirect('hidden/voucher');
}
}
I'm aware of this answer and this answer but both are related to Magento 1 and I want to make sure that they are still correct now. Further more these are related to blocks and I would think (although wrongly possibly) I can pass the model in from the controller action?
Best Answer
--We can use \Magento\Framework\Registry in your Block or Controller.
--After loading layout, get the block and set values in Controller.
--We can use setData() or getData() in our Block.
Sample: Pass model object via controller.
In your Block, you can get:
$this->_coreRegistry->registry('voucher_entity')
;