【问题标题】:Magento Helper Class Not Found ErrorMagento Helper Class Not Found 错误
【发布时间】:2011-11-06 17:21:37
【问题描述】:

我正在学习按照本教程创建自定义扩展,http://www.pierrefay.fr/category/developpement/magento

当我尝试打开扩展管理员时,我收到了Fatal error: Class 'Mage_Test_Helper_Data' not found in /var/www/html/dev/app/Mage.php on line 520

但我认为我没有在扩展中的任何地方使用辅助类。欢迎您提出建议。

这是我的 config.xml 文件

<?xml version="1.0"?>
<config>
    <modules>
        <Package_Test>
            <version>1.0.0</version>
        </Package_Test>
    </modules>
    <frontend>
        <routers>
            <routerfrontend>
                <use>standard</use>
                <args>
                    <module>Package_Test</module>
                    <frontName>test</frontName>
                </args>
            </routerfrontend>
        </routers> 
        <layout>
            <updates>
                <test>
                    <file>test.xml</file>
                </test>
            </updates>
        </layout>    
    </frontend>
    <admin> 
        <routers>
            <test>  
                <use>admin</use>
                <args>
                    <module>Package_Test</module>
                    <frontName>admintest</frontName>
                </args>
            </test>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <test>
                    <file>test.xml</file>
                </test>
            </updates>
        </layout>
        <menu>
        <test translate="title" module="adminhtml">
            <title>My Module</title>
            <sort_order>100</sort_order>
            <children>
                <items module="Test">
                    <title>Address Book</title>
                    <action>admintest/adminhtml_index</action>
                </items>
            </children>
        </test>
        </menu>
    </adminhtml>
    <global>
         <helpers>
            <class>Package_Test_Helper</class>
         </helpers>
        <blocks>
            <test>
                <class>Package_Test_Block</class>
            </test>
        </blocks>
        <models>
            <test>
                <class>Package_Test_Model</class>
                <resourceModel>test_mysql4</resourceModel>
            </test>
            <test_mysql4>
                <class>Package_Test_Model_Mysql4</class>
                <entities>
                    <test>
                        <table>package_test</table>
                    </test>
                </entities>
            </test_mysql4>
        </models>
        <resources>
            <test_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </test_write>
            <test_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </test_read>
        </resources>
    </global>
</config>

【问题讨论】:

  • 您的配置文件已损坏。 /config/global/helpers 部分有一个没有周围别名的类元素。它应该更像 /config/global/helpers/test/class
  • @blackcaps:你解决了这个问题吗,我也面临同样的问题。
  • @gowri:参考答案
  • 当我在 节点 下的 Syatem.xml 中引用错误的模块名称时,我遇到了 helper not found 问题

标签: xml magento


【解决方案1】:

如果您启用了编译,请尝试在系统、工具、编译中禁用或重新编译。

如果您无法进入管理界面但拥有 SSH 访问权限,您可以在此处禁用它:

php -f shell/compiler.php -- disable
php -f shell/compiler.php -- clear
php -f shell/compiler.php -- state

最终输出应如下所示:

Compiler Status:          Disabled
Compilation State:        Not Compiled
Collected Files Count:    0
Compiled Scopes Count:    0

【讨论】:

    【解决方案2】:

    即使您自己不使用助手,Magento 管理员也会这样做。这就是为什么你应该总是在你的扩展中包含数据助手。所以你的 Helper/Data.php 中的以下代码

    class Package_Test_Helper_Data extends Mage_Core_Helper_Abstract
    {
    
    }
    

    <global>
        <helpers>
            <test>
                <class>Package_Test_Helper</class>
            </test>
        </helpers>
    </global>
    

    在你的 config.xml 中应该足够了。

    【讨论】:

    • 我添加了它。但这并不能解决
    • 是的,我的错。我已经编辑了答案并插入了正确的类名。
    • 您现在遇到了哪个错误?确保您已将Data.php 文件放入Helper 目录
    • 我在 1.7 (EE 1.12) 中遇到了同样的问题,我不得不扩展 Mage_Core_Helper_Abstract,而不是扩展 Mage_Core_Helper_Data,然后一切正常。
    • 这里要注意的一点是,在 Unix/Linux 服务器上,文件 Data.php 必须以大写的 D 开头。
    【解决方案3】:

    为了扩展@alexei-yerofeyev 的答案,有几个地方可能会咬你。

    假设你这样定义你的助手:

    <helpers>
        <package_test>
            <class>Package_Test_Helper</class>
        </package_test>
    </helpers>
    

    您可以像这样创建一个电子邮件模板:

    <template>
        <email>
            <test_email module="package_test">
                <label>Test Email</label>
                <file>package/test_email.html</file>
                <type>html</type>
            </test_submission>
        </email>
    </template>
    

    在这种情况下,&lt;package_test&gt;module="package_test" 需要完全匹配 包括大小写。

    使用您的帮助程序的代码也是如此,如下所示:

    Mage::helper('package_test')->something();
    

    虽然这通常采用[package]_[module] 格式,但并非总是如此。您可能会遇到一个模块 Company_Widget 和一个名为 cmp_widg 的助手,您需要匹配该助手名称。

    【讨论】:

    • 再次扩展,有几个实际发生的例子in this answer
    • 谢谢,这对我来说是错的。我有 但只使用了 module="test" 并忘记输入包名。
    【解决方案4】:

    如果您添加了扩展程序并且遇到了同样的问题,那么只需手动清除缓存文件夹,因为管理员不允许进入。我遇到了同样的问题,然后我这样做了。该错误已被删除。这就是缓存错误。

    【讨论】:

      【解决方案5】:

      首先,您需要删除 var/cache 中的“缓存”文件夹 ....

      删除后转到您的 magento 根文件夹并打开 index.php 并替换代码

      找到这个代码

      /**
        * Compilation includes configuration file
        */
        define('MAGENTO_ROOT', getcwd());
        $compilerConfig = MAGENTO_ROOT . '/includes/config.php';
        if (file_exists($compilerConfig)){
          include $compilerConfig;
        }
      

      用这个代码替换

       /**
         * Compilation includes configuration file<br />
         */
         define('MAGENTO_ROOT', getcwd());<br />
         /*
          $compilerConfig = MAGENTO_ROOT . '/includes/config.php';
          if (file_exists($compilerConfig)){
            include $compilerConfig;<br />
          }
         */
      

      最后刷新你的 Magento 管理页面..

      感谢您的阅读....希望这个答案对您有所帮助。

      【讨论】:

        【解决方案6】:

        检查 Block / Adminhtml 文件中的帮助程序调用...可能是其中的某些内容调用了错误的帮助程序。

        【讨论】:

          【解决方案7】:

          我遇到了同样的问题。这真的很奇怪,因为它实际上发生在生产的克隆上。最后,我可以将问题归结为权限问题。以递归方式更改所有权限:

          To change all the directories to 755 (-rwxr-xr-x): 
          find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
          
          To change all the files to 644 (-rw-r--r--): 
          find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
          

          here 获取权限命令。祝你好运!

          【讨论】:

            猜你喜欢
            • 2015-08-31
            • 1970-01-01
            • 1970-01-01
            • 2015-02-12
            • 2023-04-03
            • 2013-10-05
            • 1970-01-01
            • 1970-01-01
            • 2023-03-25
            相关资源
            最近更新 更多