2

I want to call a helper in the main layout of my website.

I added this within the part of the layout :

<action method="addLink" translate="label title">
    <label>About us</label>
    <url helper="myModule/getAboutUsUrl" />
    <title>About us</title> 
</action>

And defined my module in the /etc/config.xml this way :

<helpers>
    <myModule>
        <class>My_Module_Helper</class>
    </myModule>
</helpers>

I created my helper My_Module_Helper_Data at the root of includes/src/.

There is no error raised, but it seems that it doesn't work. Any ideas ?

2
  • check stackoverflow.com/questions/25163730/…
    – Amit Bera
    Commented Sep 15, 2014 at 19:41
  • I already did that. (sorry, the content of my "config.xml" file didn't appear on my post, I've just edited it). The helper loads, but it's like the return value of the method "getAboutUsUrl" isn't used.
    – Laila
    Commented Sep 15, 2014 at 19:49

2 Answers 2

0

Why are you putting helper file under include/src folder? It should be under your module Helper folder.

Have you enabled compilation mode? If yes then disable that first.

Make a helper class under your module folder and that position should be: YourModuleNameSpace/ModuleName/Helper/Data.php

Class name should be: YourModuleNameSpace_ModuleName_Helper_Data

Then write your function under this class.

2
  • That was my issue thank you ! Are the classes under include/src automatically generated ?
    – Laila
    Commented Sep 15, 2014 at 20:31
  • No, Once you will complete your extension then you can again enable compilation mode from the admin panel.So when you will enable it will automatically create a reference file of your helper class into include/src folder.
    – Saurabh
    Commented Sep 15, 2014 at 20:36
3

You need create an module which define new helper types.

Step1: config.xml at app/code/local/My/Module/ and it code should be

<?xml version="1.0"  encoding="UTF-8"?>
<config>
    <modules>
        <My_Module>
            <version>1.1.0</version>
        </My_Module>
    </modules>
    <global>
        <helpers>
            <mymodule>
                <class>My_Module_Helper</class>
            <mymodule>
        </helpers>
    </global>
</config>

Step2: create Data.php at app/code/local/My/Module/Helper/

class My_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function getAboutUsUrl()
    {
        //you code
    }
}

Step3: create My_Module.xml at app/etc/modules/ and code is

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <My_Module>
            <codePool>local</codePool>
            <active>true</active>
        </My_Module>
    </modules>
</config>

Step4: Disable Compiler and clear cache from admin and check y_Module in admin > system > Configuration > .. > Advance

Step5: enable compiler again

Step6: add new link by add below code at layout file at local.xml at app/design/frontend/your_package/your_template/layout/ and put this code

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="top.links">
            <action method="removeLinkByUrl"><url helper="customer/getAccountUrl" /></action>
            <action method="addLink" translate="label title" module="mymodule">
                <label>About us</label>
                <url helper="mymodule/getAboutUsUrl" />
                <title>About us</title> 
            </action>
        </reference>
    </default>
</layout>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.