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('VendorPakkeBlockTrackInfoTrackingInfo')
->setTemplate('Vendor_Pakke::track_info.phtml')
->setTrackingInfo($pakkeShipment)
->toHtml();
$this->getResponse()->setBody($block);
}
Block.php
class TrackingInfo extends Template
{
public $trackingData;
public function __construct(
TemplateContext $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"?>
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.