我想声明一些PHP函数,我想在magento中的各个地方调用这些函数。通常在我的核心PHP项目中,我声明了php函数在functions.php和我将这个文件包含在所有页面中。我不熟悉MVC结构。因此,我可以在哪里声明这些类型的函数。我可以在哪里声明我的自定义函数在magento
由于
编辑: -
Mango_Myfunc.xml(表观的/ etc /模块)
<?xml version="1.0"?>
<config>
<modules>
<Mango_Myfunc>
<active>true</active>
<codePool>local</codePool>
</Mango_Myfunc>
</modules>
</config>
的Config.xml(应用程序/代码/本地/芒果/ MYFUNC /etc/configure.xml)
<?xml version="1.0"?>
<config>
<modules>
<Mango_Myfunc>
<version>0.1.0</version>
</Mango_Myfunc>
</modules>
<global>
<helpers>
<Myfunc>
<class>Mango_Myfunc_Helper</class>
</Myfunc>
</helpers>
</global>
</config>
Data.php(应用程序/代码/本地/芒果/ MYFUNC /帮手/ Data.php)
class Mango_Myfunc_Helper_Data extends Mage_Core_Helper_Abstract
{
public function short_str ($str, $len, $suf = '...') {
if (strlen($str) > $len)
return substr($str, 0, $len - strlen($suf)) . $suf;
return $str;
}
}
这是我加入
我用波纹管一个调用列表的功能。 PHTML
echo $this->helper('Myfunc/Data')->short_str("test","3"); got the error
致命错误:类 'Mage_Myfunc_Helper_Data' 未找到
看起来不错。你刷新了缓存吗? – Nick
@Nick:是的,现在有效,谢谢 – Gowri
并注意那些方法可能已经存在于核心助手中,您可能会先尝试观察它们 –