-1

一直在尝试从 magento 中的 .phtml 文件中的两个辅助函数中获取可变百分比

基本上我有两个变量,它们基于两个辅助函数,它们自己的输出/回显静态数字。问题出在下面的 php 中,它们只是显示为值而不是除/乘。所以就像我说的帮助数据和模块的工作是使用数据作为变量来完成/完成 .phtml 文件中的方程。请参阅下面的代码

get->FunctionA()刚好等于一个整数值(来自一个集合)

get->FunctionB()也只是等于一个整数值(来自一个集合)

可能不是最好的方法,但这只是从帮助数据中输出两个值而不是除法。

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

这也不起作用,只会产生相同的结果,并且是最好/最简单的方法

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

就像我在上面所说的那样,可以回显这些值(在辅助函数或 phtml 文件中,但实际计算不会起作用

任何帮助都会很棒

4

1 回答 1

1

好的解决了问题。发生的事情是,在帮助文件中,当我应该只是返回值然后在 .phtml 文件中回显辅助函数时,正在回显 getFunctionA() 和 getFunctionB() 值。嗬!请参阅下面的帮助函数示例,现在正在运行 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

}

现在可以在 phtml 中回显该值并确认数学方程有效

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

这段代码做数学运算,现在我可以休息了。

于 2014-05-03T23:11:25.543 回答