【问题标题】:Magento with Custom Helper Function failed to open具有自定义帮助功能的 Magento 无法打开
【发布时间】:2014-07-28 08:12:23
【问题描述】:

我做了两次全新的 magento 1.9.0.1 安装,一次在我的电脑中使用 wampserver(apache 2.44,php5.4.12),第二次在我的共享主机中使用 nginx 和 php5.4.4,两者都工作 [b]fine [/ b]日志中没有错误。

我用一个 Helper 类创建了一个简单的函数来比较税号 p.e.:

app/etc/modules/MyF_checkF.xml

<config>
    <modules>
        <MyF_checkF>
            <active>true</active>
            <codePool>local</codePool>
        </MyF_checkF>
    </modules>
</config>

app/code/local/MyF/checkF/etc/config.xml

<config>
     <global>
         <helpers>
            <checkF>
                <class>MyF_checkF_Helper</class>
            </checkF>
        </helpers> 
     </global>
 </config>

app/code/local/MyF/checkF/Helper/Data.php

<?php

class MyF_checkF_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function validVAT($vat)
    {
        if($vat == 123) 
                    return TRUE;
            else 
                    return FALSE;
    }
}

将 /app/code/core/Mage/Customer/Model/Customer.php 复制到 /app/code/local/Mage/Customer/Model/Customer.php 并在税后检查后添加

if ($attribute->getIsRequired() && !Mage::helper('checkF')->validVAT($this->getTaxvat())){
            $errors[] = Mage::helper('customer')->__('TAX/VAT wrong.');
            }

在我的 PC localhost 中正常工作,日志干净,但在我得到的共享主机中:

系统日志

Warning: include(Mage/CheckF/Helper/Data.php): failed to open stream: No such file or directory  in /var/www/clients/client0/web10/web/lib/Varien/Autoload.php on line 93
Warning: include(): Failed opening 'Mage/CheckF/Helper/Data.php' for inclusion (include_path='/var/www/clients/client0/web10/web/app/code/local:/var/www/clients/client0/web10/web/app/code/community:/var/www/clients/client0/web10/web/app/code/core:/var/www/clients/client0/web10/web/lib:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client0/web10/web/lib/Varien/Autoload.php on line 93

错误日志

FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'Mage_CheckF_Helper_Data' not found in /var/www/clients/client0/web10/web/app/Mage.php on line 547" while reading response header from upstream, request: "POST /index.php/customer/account/createpost/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9019"

两个安装都禁用了 magento 缓存,我知道为什么在共享主机中 magento 会寻找 Mage/CheckF.. 而不是 local/checkf,但在 localhost 中有效。

感谢您的帮助!

【问题讨论】:

    标签: magento nginx mage


    【解决方案1】:

    需要将助手 checkF 更改为 checkf ... 并使用Mage::helper('checkF') 而不是Mage::helper('checkf')

    <?xml version="1.0"?>
    <config>
        <modules>
            <MyF_checkF>
                <version>0.1.0</version>
            </MyF_checkF>
        </modules>
         <global>
             <helpers>
                <checkf>
                    <class>MyF_checkF_Helper</class>
                </checkf>
            </helpers> 
         </global>
     </config>
    

    【讨论】:

      【解决方案2】:

      警告:include(Mage/CheckF/Helper/Data.php): 无法打开流,它试图在 Mage 包而不是您的自定义模块 MyF 中定位,这可能会给您一个线索,

      并将您的名称,MyF_checkF_Helper_Data 更正为 MyF_CheckF_Helper_Data,因为 Magento 自动从目录中加载类

      【讨论】:

      • 谢谢!!问题是 checkF 的大写。
      猜你喜欢
      • 2011-11-06
      • 1970-01-01
      • 2021-03-12
      • 2018-07-10
      • 1970-01-01
      • 2012-01-03
      • 2017-03-02
      • 2019-04-14
      • 1970-01-01
      相关资源
      最近更新 更多