I need to send data from controller to Block, I have used many ways but it does not work. I'm trying this way:
Controller.php
public function execute()
{
$order_id = $this->getRequest()->getParam("order_id");
$order = $this->orderInterface->loadByIncrementId($order_id);
$pakkeShipment = $order->getPakkeShipment();
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__(' heading '));
$block = $resultPage->getLayout()
->createBlock('Vendor\Pakke\Block\TrackInfo\TrackingInfo')
->setTemplate('Vendor_Pakke::track_info.phtml')
->setTrackingInfo($pakkeShipment)
->toHtml();
$this->getResponse()->setBody($block);
}
Block.php
class TrackingInfo extends Template
{
public $trackingData;
public function __construct(
Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
}
public function setTrackingInfo($trackingData){
$this->trackingData = $trackingData;
}
public function getTrackingInfo(){
return $this->trackingData;
}
}
pakke_index_index.phtml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block class="Vendor\Pakke\Block\TrackInfo\TrackingInfo" name="tracking_info" template="Vendor_Pakke::track_info.phtml" />
</referenceContainer>
</page>
I get an error in this way, I just want to send $pakkeShipment
to setTrackingInfo()
so I can use the method getTrackingInfo();
in my phtml.