簡體   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