php 在 Magento 中调用助手类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9347831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:37:52  来源:igfitidea点击:

Calling a helper class in Magento

phpmagentoe-commercehelpers

提问by Jason Millward

I'm trying to create a custom helper module in Magento but I'm getting the following error when I call it from a page :

我正在尝试在 Magento 中创建一个自定义帮助程序模块,但是当我从页面调用它时出现以下错误:

Warning: include(Mage/SEO/Helper/Data.php) [function.include]: failed to open stream: No such file or directory  in /home/strailco/1stclassholidays.com/html/lib/Varien/Autoload.php on line 93

From the template i am using the following to call the helper module:

从模板中,我使用以下内容来调用帮助器模块:

<?php echo Mage::helper('SEO')->getFullProductUrl($product); ?>

The helper module is set up under:

辅助模块设置在:

/app/code/local/SEO/Fullurl/Helper/Data.php
/app/code/local/SEO/Fullurl/etc/config.xml

Data.php calls the function:

Data.php 调用函数:

<?php 

class getFullProductUrl {

public function getFullProductUrl( $product )
{
}

I have my config.xmlset up like this:

我的config.xml设置如下:

<?xml version="1.0"?>
<config>
     <global>
        <helpers>
        <SEO>
        <class>getFullProductUrl</class>
        </SEO>
        </helpers>
   </global>
</config>

I think the problem is the way I have the config.xml set up but I'm struggling to work out the correct way of doing this.

我认为问题在于我设置 config.xml 的方式,但我正在努力找出正确的方法。

I would be very greatful of any help that you could give. I've been working on this for a couple of days but can't get it working.

如果您能提供任何帮助,我将不胜感激。我已经为此工作了几天,但无法使其正常工作。

Many Thanks

非常感谢

Jason

杰森

回答by Max

Your first problem is the config.xml. You have to tell Magento which class you're using.

您的第一个问题是 config.xml。你必须告诉 Magento 你正在使用哪个类。

...Other Stuff...
<global>
  ...Other Stuff...
  <helpers>
    <SEO>
      <class>SEO_Fullurl_Helper</class>
    </SEO>
   </helpers>
   ...Other Stuff...
</global>
...Other Stuff...

Then you need a Helper in app/code/local/SEO/Fullurl/Helper/Data.phpthat looks like this:

然后你需要一个app/code/local/SEO/Fullurl/Helper/Data.php看起来像这样的助手:

class SEO_Fullurl_Helper_Data extends Mage_Core_Helper_Abstract
{

    function getFullProductUrl( $product )
    {
    }
}

Then you can do echo Mage::helper('SEO')->getFullProductUrl($product);

然后你可以做 echo Mage::helper('SEO')->getFullProductUrl($product);

回答by nickspiel

I had missed the step of adding the module to app/etc/modules/SEO_Fullurl.xml

我错过了将模块添加到 app/etc/modules/SEO_Fullurl.xml 的步骤

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

I hope this helps someone, very easy mistake to make.

我希望这对某人有所帮助,很容易犯错误。