【问题标题】:How to call a function in a block from another phtml in magento如何从magento中的另一个phtml调用块中的函数
【发布时间】:2015-09-28 17:23:05
【问题描述】:

你如何在magento的另一个模块中从另一个phtml调用一个模块中的块中的函数?我有一个view.php 块文件。它里面有函数,比如getproduct()getproduct() 函数需要调用另一个文件product.phtml 中的函数,该文件位于另一个模块中。我该如何做到这一点?

【问题讨论】:

  • 请出示您尝试过的代码,以便其他人可以帮助您。

标签: magento-1.4


【解决方案1】:

如果两个块在同一页面中使用:

$block = $this->getLayout()->getBlock('block_name'); // get block
$block->getProduct(); // call function from block

如果您需要在自定义页面中屏蔽:

$block = $this->getLayout()->createBlock('block_type'); // creation of the block
$block->getProduct(); // call function from block

但如果你只需要当前的产品,那你为什么不从 Mage::registry 获取呢?

$product = Mage::registry('current_product');

【讨论】:

    猜你喜欢
    • 2016-05-22
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2014-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多