Thursday, February 12, 2015

include custom library functions

We are going to create a Magento helper.

app/code/local/My/Blockgen/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <My_Blockgen>
            <version>1.0.0</version>
        </My_Blockgen>
    </modules>
    <global>
        <helpers>
            <blockgen>
                <class>My_Blockgen_Helper</class>
            </blockgen>
        </helpers>
    </global>
</config>

app/etc/modules/My_Blockgen.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <My_Blockgen>
            <active>true</active>
            <codePool>local</codePool>
        </My_Blockgen>
    </modules>
</config>

app/code/local/My/Blockgen/Helper/Stdlib.php:

<?php
class My_Blockgen_Helper_Stdlib extends Mage_Core_Helper_Abstract
{
  public function sayHello()
  {
    return 'Hello World!';
  }   
}
?>

Test the function:

$helper = Mage::helper('blockgen/stdlib');
echo $helper->sayHello();

Or

echo Mage::helper('blockgen/stdlib')->sayHello();

No comments: