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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题