Calling a helper class in Magento

Jason Millward picture Jason Millward · Feb 19, 2012 · Viewed 38.3k times · Source

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

Answer

Max picture Max · Feb 19, 2012

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);