繁体   English   中英

如何将.phtml文件变量传递给magento2中的另一个模块.phtml文件

[英]How to pass .phtml file variable to another module .phtml file in magento2

我是magento的新手。 如果有人知道如何做到这一点,请告诉我。 我在不同的模块中有两个文件,其中两个 .phtml 文件将在那里。 从第一个 .phtml 文件到另一个 .phtml 文件我想传递数组变量我不知道如何传递它。

第一个文件路径如下,带有 php 变量:

/var/www/html/MyProject/app/design/frontend/Megnor/mag110246_4/Lof_CustomerMembership/templates/customer/membership/transactions.phtml

在这个文件中,我有 $transaction 变量,我想发送另一个 info.phtml

<?php
/** @var \Magento\Customer\Block\Account\Dashboard\Address $block */

$helper = $this->helper("Lof\CustomerMembership\Helper\Data");
$transactions = $block->getTransactions();
$address=$block->getPrimaryBillingAddress();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerId =$customerSession->getCustomer()->getId();
 $activeOrNot="";
?>

另一个文件路径将是:

/var/www/html/MyProject/app/design/frontend/Megnor/mag110246_4/Magedelight_SMSProfile/templates/account/dashboard/info.php

在 info.php 文件中,我想要 $transactions 数组变量

任何人都知道如何做到这一点然后请告诉我

您的 getTransactions() 函数在您的块中。 所以只需将该块重用于您的另一个 phtml 文件。

三个选项,

  1. 只需将您的函数从交易块复制到信息块,所有相关的变量和结构。

  2. 从信息块,从交易块创建对象,并通过该对象创建 getTransactions() 函数

  3. 只需使用直接调用它

    $blockObj= $block->getLayout()->createBlock('Company\ModuleName\Block\ClassName');

    回声 $blockObj->getTransactions();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM