Create Global Function In Magento
Posted: June 9th, 2011 | Author: jriggs | Filed under: magento, web | Tags: global function magento | 2 Comments »This code will allow you to add a function that can be called from anywhere within Magento. It extends the helper class
1) Create a file named ‘Mycode.xml’ and copy it to app/etc/modules/ – it should look like this:
<?xml version="1.0"?> <config> <modules> <Mycode_Function> <active>true</active> <codePool>local</codePool> </Mycode_Function> </modules> </config>
2) Create the directory
app/code/local/Mycode/Function/etc
and then create a file named ‘config.xml’
In it copy:
<?xml version="1.0"?> <config> <modules> <Mycode_Function> <version>1.0.0</version> </Mycode_Function> </modules> <global> <helpers> <function> <class>Mycode_Function_Helper</class> </function> </helpers> </global> </config>
3) Create the directory
app/code/local/Mycode/Function/Helper
and then create a file named ‘Data.php’
In it copy:
<?php class Mycode_Function_Helper_Data extends Mage_Core_Helper_Abstract { public function test(){ return 'works'; } }
You can now call this function like so
<?php echo Mage::helper('function')->test(); ?>
Related posts:
- Create Blank Page for WordPress Blog Using Your Theme Template
- Block Spammers by IP address in WordPress
- php: Create Url Safe Encrypted String
- Show Close Button In Last Tab with Firefox 3.5
- Remove New Tab Button From Firefox 3.5







Correct is:
echo Mage::helper(‘mycode/function’)->test();
[...] in their site. Before I start I should give credit for this post to Joe Riggs for his post here: http://joe-riggs.com/blog/2011/06/create-global-function-in-magento/ – it gives a nice tutorial on how to include your own custom functions in Magento by simply [...]