在 Magento 中调用辅助类

发布于 2025-01-06 19:36:57 字数 1113 浏览 3 评论 0原文

我正在尝试在 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

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

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

帮助程序模块设置如下:

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

Data.php 调用该函数:

<?php 

class getFullProductUrl {

public function getFullProductUrl( $product )
{
}

我的 config.xml 设置如下:

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

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

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

非常感谢

杰森

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 :

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:

<?php 

class getFullProductUrl {

public function getFullProductUrl( $product )
{
}

I have my config.xml set up like this:

<?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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幻想少年梦 2025-01-13 19:36:57

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

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

然后您需要在 app/code/local/SEO/Fullurl/Helper/Data.php 中添加一个如下所示的 Helper:

class SEO_Fullurl_Helper_Data extends Mage_Core_Helper_Abstract
{

    function getFullProductUrl( $product )
    {
    }
}

然后您可以执行 echo Mage::helper('SEO') ->getFullProductUrl($product);

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

...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.php that looks like this:

class SEO_Fullurl_Helper_Data extends Mage_Core_Helper_Abstract
{

    function getFullProductUrl( $product )
    {
    }
}

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

神回复 2025-01-13 19:36:57

我错过了将模块添加到 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 had missed the step of adding the module to 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文