Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 3
How to use a custom module’s helper in other modules (ie catalog)
 
Mistbringer
Jr. Member
 
Total Posts:  1
Joined:  2008-01-30
 

Hi,
I guess the answer is deceptively simple but after a hour of searching I cannot find a solution.

I created and enabled a custom module, which has a helper, that I would like to use in the other pages, named “cover”

So, in the “catalog/product/list.phtml” file, when I try to use $this->helper("company/module")->cover(..) , I get an error,

Fatal error: Class ‘Mage_Company_Helper_Module

since the helper method is looking in Mage folder,

What is the correct way to call a helper in another “local” custom module?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

when you call $this->helper() the syntax is ‘yourmodulealias/helpername’.

So, if you use

<config>
    <global>
        <
helpers>
            <
yourmodule>
                <class>
YourCompany_YourModule_Helper</class>
            </
yourmodule>
        </
helpers>
    </global>
</
config>

and you have a helper you wrote called YourCompany_YourModule_Helper_Helpme with a method called cover(), you would use this syntax

$this->helper('yourmodule/helpme')->cover();

If you do not specify a helper, it defaults to YourCompany_YourModule_Helper_Data

$this->helper(’yourmodule’) === $this->helper(’yourmodule/data’)

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Also, keep in mind, the <rewrite> element works for helpers just like most other things.

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

I am trying to call a custom modules helper in the header.phtml file. I have tried

$this->helper('customsearch/data')->getRaceSeriesOptions();

and

Mage::helper('customsearch/data')->getRaceSeriesOptions();

Both give me an error of “Mage_Customsearch_Helper_Data’ not found”.

My helper is located in app/code/local/Essex/CustomSearch/Helper/Data.php and it extends Mage_Core_Helper_Abstract.

I am pretty sure that the helper is set up correctly.
Is there any trick to tell magento that I want to use Essex_CustomSearch_Helper_Data instead of Mage_CustomSearch_Helper_data.

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

You must name the folder “Customsearch” as Unices are case-sensitive (bit me yesterday when I deployed some code developed on Windows to a Linux host confused)

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

I am developing on a windows machine right now so if that were the only problem then it should be working for me, but it is not. Thanks for the reply though.

 
Magento Community Magento Community
Magento Community
Magento Community
 
J!Code
Jr. Member
 
Avatar
Total Posts:  12
Joined:  2009-04-09
The Hague
 

Did anyone found a solution for this?
I’m running into the same problem with a helper i wrote.
Everything is as it should be, but i keep getting the error:

Fatal error: Call to undefined method Mage_Catalog_Helper_Product_Compare::isAllow() in D:\Projects\test environment\directapotheek.nl\app\design\frontend\default\blank_seo\template\catalog\product\list.phtml on line 36

But the method isAllow() is in my own helper.. not in the mage code..

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

Post your config.xml, maybe the error is there.

 
Magento Community Magento Community
Magento Community
Magento Community
 
J!Code
Jr. Member
 
Avatar
Total Posts:  12
Joined:  2009-04-09
The Hague
 

<?xml version="1.0"?>
  
<config>
    <global>
      <
helpers>
        <
catalog>
          <
rewrite>
            <class>
Open365_Catalog_Helper_Product</class>
          </
rewrite>
        </
catalog>
      </
helpers>
    </global>
</
config>

This is my config.xml

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

@Jeroen
I believe I used this for mine and it finally worked Mage::helper(’customsearch’)->getRaceSeriesOptions();

 
Magento Community Magento Community
Magento Community
Magento Community
 
magentoadmindeveloper
Jr. Member
 
Total Posts:  6
Joined:  2009-09-13
 

what is the purpose of helper in magento

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

It’s a class where you collect utility functions pertinent to a module, mostly to use them in templates. It’s somehow related to models, but those are supposed to produce/work on data, whereas helpers don’t change anything (in the DB, for example), they just transform data or maybe look something up for you.
One example of a helper is the ‘core/string’ helper, it has functions like htmlEscape() and some string functions etc.

 
Magento Community Magento Community
Magento Community
Magento Community
 
magentoadmindeveloper
Jr. Member
 
Total Posts:  6
Joined:  2009-09-13
 

Thanks night fly

 
Magento Community Magento Community
Magento Community
Magento Community
 
magentoadmindeveloper
Jr. Member
 
Total Posts:  6
Joined:  2009-09-13
 

Can anyone please help me in adding a submenu in the admin panel
For ex:I need to add one submenu under CMS Menu

CMS ->(1)Managepages,(2)staticblocks,(3)pollmanager
and the new one I am going to add
(4)manage items

 
Magento Community Magento Community
Magento Community
Magento Community
 
golohvastov
Jr. Member
 
Total Posts:  11
Joined:  2009-01-26
 

just spent few hours sorting out this thing for myself.
Realised that for helpers you should NOT preceed module name with namespace like you do for blocks.
for example the block I declared this way
<blocks>
<Osnova_WpPost>
<class>Osnova_WpPost_Block</class>
</Osnova_WpPost>
</blocks>
but helpers I’ve done just like that.
<helpers>
<WpPost>
<class>Osnova_WpPost_Helper</class>
</WpPost>
</helpers>

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

Prefix or not doesn’t matter. If you declare your helpers with Osnova_WpPost, you get them with Mage::helper(’Osnova_WpPost’), I guess, unless some upper/lower/camelcasing happens, which is why I always declare them in lowercase so I won’t get troubles. Like osnova_wppost.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3