【问题标题】:Fatal error helper class Magento 1.9致命错误助手类 Magento 1.9
【发布时间】:2015-03-29 21:45:14
【问题描述】:

我是 Magento 的新手。我创建了一个帮助类

/app/etc/modules/Mytrends_MyFunctions.xml 文件:

<?xml version="1.0"?>
<config>
    <modules>
        <Mytrends_MyFunctions>
            <active>true</active>
            <codePool>local</codePool>
        </Mytrends_MyFunctions>
    </modules>
</config>

/app/code/local/Mytrends/MyFunctions/etc/config.xml:

<?xml version="1.0"?>
<config>
<modules>
        <Mytrends_MyFunctions>
            <version>1.0.0</version>
        </Mytrends_MyFunctions>
    </modules>
    <global>
        <helpers>
            <myfunctions>
                <class>Mytrends_MyFunctions_Helper</class>
            </myfunctions>
        </helpers>
     </global>
</config>

/app/code/local/Mytrends/MyFunctions/Helper/Data.php:

<?php
class Mytrends_MyFunctions_Helper_Data extends Mage_Core_Helper_Abstract
{
        public function test () {
            echo 'hello';
        }
}
?>

我试着像这样调用这个 test()

Mage::helper('myfunctions')->test();

但我遇到了一个致命错误:

Fatal error: Class 'Mytrends_MyFunctions_Helper_Data' not found in /app/Mage.php on line 548

请帮忙。

【问题讨论】:

  • 您是否尝试过刷新配置缓存?
  • 一个你应该真正放松的坏习惯是关闭一个类的 php。你永远不应该这样做。请阅读stackoverflow.com/questions/4410704/

标签: php magento


【解决方案1】:

你必须像这样调用辅助函数:

Mage::helper('mytrends/myfunctions')->test();

请试试这个。

【讨论】:

    【解决方案2】:

    请正确检查您的模块 config.xml 文件路径。

    【讨论】:

    • 对不起,是我的错,我这里写错了文件名。
    【解决方案3】:

    这个文件不需要正确的名字:/app/etc/modules/config.xml它应该是/app/etc/modules/Mytrends_MyFunctions.xml

    【讨论】:

    • 对不起,是我弄错了,这里写错了文件名。
    • 除此之外,我乍一看没有发现任何错误。你确定你没有放错文件?查看您的错误,它看起来像是来自文件 /app/code/local/Mytrends/MyFunctions/Helper/Data.php 的错误被放错了位置,或者这个助手的类名被错误地输入了。
    猜你喜欢
    • 2018-09-29
    • 2018-12-12
    • 2014-09-22
    • 1970-01-01
    • 2016-01-02
    • 2013-02-23
    • 2012-11-14
    • 2013-03-21
    • 2016-10-08
    相关资源
    最近更新 更多