Magento Expert Forum - Improve your Magento experience

Results 1 to 5 of 5

How To Create A Helper In Magento

  1. #1
    Junior Member fay_khattak's Avatar
    Join Date
    Jan 2016
    Location
    Karachi, Pakistan
    Posts
    50
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Post How To Create A Helper In Magento

    Due to some good reasons, it’s a bad programming habit, and it’s not recommended at all if you modify the core files of Magento. But sometimes, you may want to add new classes or override different functions in your Magento module. Therefore, Magento came up with the Helpers that are the right entity to fulfill your needs.

    A Helper in Magento is an object that contains practical methods. You can call it in template files, controllers, models or anywhere in Magento. All you need is to load your helper like this:

    Mage::helper('MODULE_NAME/HELPER_CLASS')->HELPER_FUNCTION();

    Creating a Helper is quite easy. In this tutorial, you will learn how to create a helper in Magento. You will also find out how to use a helper!

    How To easily creat Magento Helper

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Jan 2016
    Location
    Rajkot, Gujarat, India
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Hi,

    Did you check the following tutorial about Create A Helper In Magento?

    http://www.pierrefay.com/magento-hel...o-tutorial-113

    This will work fine for me, hope this will work best for you also.

    Thanks

  3. #3
    Junior Member knowband.plugins's Avatar
    Join Date
    Jul 2016
    Location
    Noida, India
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    First create a module named mymodule(You can name it whatever you want). The path will be Home/app/code/local/Test/Mymodule.
    1. Add the below in within the global tag in Home/app/code/local/Test/Mymodule/etc/config.xml

    <helpers>
    <mymodule>
    <class>MyExtensions_Mymodule_Helper</class>
    </mymodule>
    </helpers>

    2. Create a file Home/app/code/local/Test/Mymodule/Helper/Calculator.php

    <?php
    class MyExtensions_Mymodule_Helper_Calculator extends Mage_Core_Helper_Abstract
    {
    public function add($a, $b)
    {
    return $a + $b;
    }

    ?>


    You can call the helper in following way

    $result = Mage::helper('Mymodule/Calculator')->add(2,3);


    Here $result will have value returned from helper.

    Check our Magento Extensions at Knowband.com

  4. #4
    Junior Member
    Join Date
    Aug 2016
    Posts
    72
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    Magento Developer's Guide this tutorial is the 12th of many tutorials. you will now learn how to create your helper in Magento. As the name implies a <<helper>> is something that is right for you ! It is an object that will contain practical functions for you and you can call it from anywhere you just load your helper to use it.
    Example: $helper= mage::helper('monhelper');

  5. #5
    Junior Member
    Join Date
    Sep 2018
    Location
    Oman, Muscat
    Posts
    2,084
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    You can call it in template files, controllers, models or anywhere in Magento. All you need is to load your helper like this: Mage::helper('MODULE_NAME/HELPER_CLASS')->HELPER_FUNCTION(); Creating a Magento Helper is quite easy.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •