doqvzh345334 2014-05-03 11:12
浏览 17
已采纳

在magento中获取帮助数据php

Have been trying to get a variable percentage from two helper functions inside .phtml file in magento

basically i have two variables based on two helper functions that on their own output/echo static numbers. Problem is in the below php they are just displaying as the value and not dividing/multiplying. So like i said the helper data & module work is using the data as variables to do/complete the equation within the .phtml file. See code below

get->FunctionA() just equals a round number value (from a collection)

get->FunctionB() just equals a round number value as well (from a collection)

probs not the best way but this just outputs two values from helper data and not dividing.

echo Mage::helper('module/data')->getFunctionA() / Mage::helper('module/data')->getFunctionB();

Also this does not work either, just produces the same result and is probs the best/easiest way

$dataA = Mage::helper('module/data')->getFunctionA(); 
$dataB = Mage::helper('module/data')->getFunctionB();
$result = ($dataA / $dataB) * 100;
echo $result;

Like i said above the values can be echoed (in either helper function or phtml files but the actual calculation does not wont to work

Any help would be great

  • 写回答

1条回答 默认 最新

  • dqpfl2508589 2014-05-03 23:11
    关注

    Ok sorted the problem out. What was happening was that in the helper file the getFunctionA() & getFunctionB() value was being echoed when i should have been just returning the value then echoing the helper function in the .phtml file. Doh! See below the helper function example that is now working Woohoo!!!

    public function getFunctionA()
    {
    $FunctionA = Mage::getModel('module/collection')->getCollection();
    $FunctionA->addFieldToFilter('attribute', 'value_to_filter');
    $FunctionA->addFieldToFilter('status','1');
    return ''.count($FunctionA) . ''; //this line was the problem cause i was echoing & not returning the value
    
    }
    

    Now the value can be echoed in the phtml & the math equation is confirmed working

    $dataA = Mage::helper('module/data')->getFunctionA(); 
    $dataB = Mage::helper('module/core')->getFunctionB();
    $result = ($dataA / $dataB) * 100;
    echo $result;
    

    this code does the math and now i can rest.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘