分类
后端

Magento2 controller 如何传值给phtml

use Magento\Framework\Controller\ResultFactory; 

$page = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
// message.edit  是layout name值
        $block = $page->getLayout()->getBlock('message.edit');
        $block->setData('message_data', $data);
        return $page;