Magento Expert Forum - Improve your Magento experience
-
Junior Member
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:
-
-
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
-
-
Junior Member
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
-
-
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');
-
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks