confused squirrel

Joomla 3 Helper File Instructions

For my friends who don’t care about tech, just ignore this post.

If you are a Joomla developer, maybe you’ll find these notes helpful. I’m writing them down at the end of another week of circling through Joomla tutorials trying to get something to work the way I want. As is all too common, the instructions were contradictory and it seemed that every one left out some crucial piece of information. Hopefully I haven’t missed including any of the steps, because I’ve tried more variations than I can remember right now.

My goal: create a function that could be used anywhere in my component.

This was a true “helper” function and I needed it everywhere.

Here’s what I had to do to make it work:

  • start with a component com_mycomponent
  • in administrator/com_mycomponent/mycomponent.php add this line:
    JLoader::register(‘MycomponentHelpersMycomponent’, JPATH_COMPONENT . ‘/helpers/mycomponent.php’);
  • in administrator/com_mycomponent/helpers/ add mycomponent.php
  • in that file include these lines:
    abstract class MycomponentHelpersMycomponent
    {
          public static function mycustomfunction($params)
           { code your function here
            }
    }
  • when you want to use the function, just use this line:
    $result = MycomponentHelpersMycomponent::mycustomfunction($params);

Simple, right? Each bit of camel case is critical. You can use whatever $params you need (or none at all).

When I figure out how to make it work on the front end, too, I’ll update this post.

Maybe next time I can get this to work before 1AM.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *