Wednesday, March 14, 2012

[Joomla] Include Helper Class

Helpers, in my own understanding, are some of the Joomla files that are usually use when they can't be classified either as a mode, view, or controller. So when we intend to use them, we need to include them. There are many way on how to include helpers like using include, include_once, require, or require_once but because we are using Joomla it would be cool to use the Joomla way. And just like in including the helper file in PHP, there are also many ways to do it but I will only show one of the many ways because this is what I usually use.

JLoader::register('HelperClassName', dirname(__FILE__) . DS . 
     'helpers' . DS . 'helper.php');


JLoader is a class that handles loading libraries or other files (like helpers)
register is a method in JLoader that register a class to autoload list. It accepts two parameters. The first one is the name of the class where in our example is HelperClassName. The second one is the location of the file.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...