简体   繁体   English

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

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

I am new in the magento.我是magento的新手。 If anyone have idea how to do this then please let me know.如果有人知道如何做到这一点,请告诉我。 I have two files in different module in in that two .phtml file will be there.我在不同的模块中有两个文件,其中两个 .phtml 文件将在那里。 From First .phtml file to another .phtml file i want pass array variable I am not getting how to pass that.从第一个 .phtml 文件到另一个 .phtml 文件我想传递数组变量我不知道如何传递它。

First file path as follows with php variable:第一个文件路径如下,带有 php 变量:

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

In this file i have $transaction variable that i want to send another info.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="";
?>

Another file path will be:另一个文件路径将是:

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

In the info.php file i want that $transactions array variable在 info.php 文件中,我想要 $transactions 数组变量

Anyone have idea how to do this then please let me know任何人都知道如何做到这一点然后请告诉我

Your getTransactions() function inside in your block.您的 getTransactions() 函数在您的块中。 so just reuse the block for your another phtml file.所以只需将该块重用于您的另一个 phtml 文件。

Three options,三个选项,

  1. just copy your function from transactions block to info block, all related variables and constructions too.只需将您的函数从交易块复制到信息块,所有相关的变量和结构。

  2. From info block, create object from transactions block and this object to create getTransactions() function从信息块,从交易块创建对象,并通过该对象创建 getTransactions() 函数

  3. Simply call it directly using只需使用直接调用它

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

    echo $blockObj->getTransactions();回声 $blockObj->getTransactions();

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

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