Calling a helper class in Magento

38,629

Solution 1

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

Solution 2

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.

Share:
38,629
Jason Millward
Author by

Jason Millward

Updated on December 05, 2020

Comments

  • Jason Millward
    Jason Millward over 3 years

    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

    • Leoh
      Leoh over 7 years
      I have a similar error with a another modules: ERR (3): Warning: include(Mage/Adjgiftreg/Helper/Data.php): failed to open stream: No such file or directory in ... where do you call echo Mage::helper('SEO')->getFullProductUrl($product); ??
  • Jason Millward
    Jason Millward about 12 years
    Thanks for the reply - in config.xml when you say "other stuff..." what do you mean? Am I missing something from the file?
  • Max
    Max about 12 years
    You are missing a lot of stuff! Read alanstorm.com/magento_config to learn about the configuration files. If you want Blocks, Controllers, or Models you will have to declare them in config.xml also. Read more on alanstorm.com/category/magento