We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

EE2x: How do I create custom plugin / module helper functions?

Development and Programming

Rob Hawkes's avatar
Rob Hawkes
5 posts
about 16 years ago
Rob Hawkes's avatar Rob Hawkes

Hello,

I’m trying to move some of my plugin functions into a dedicated helper function for the plugin, within a “/helpers” directory within the plugin directory.

However, I’ve tried this and when using…

$this->EE->load->helper('test');

…it gives me an error saying the file cannot be loaded, even though “test_helper.php” exists in “…/third_party/myplugin/helpers/test_helper.php”.

Am I doing something wrong? Or is there no way to have custom helpers stored within the plugin directory? I want to stay away from storing my helpers outside of the plugin directory.

For reference, the docs state that third-party packages can have their own helper functions.

Regards, Rob

Moved to Plugins by Moderator

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
about 16 years ago
Sue Crocker's avatar Sue Crocker

Hi, Rob. Unfortunately we don’t officially offer technical support for writing plugins/etc. in EE. I’m moving this to the Plugins folder for additional community support.

       
Rob Hawkes's avatar
Rob Hawkes
5 posts
about 16 years ago
Rob Hawkes's avatar Rob Hawkes

I suppose what I’m really asking is this…

The documentation on using custom helper functions within packages in EE2 is lacking at best, so does anything have any examples of plugins/extensions/modules that use their own helper functions in EE2? I’m itching to work out how to load my own helper functions into EE2 without having to move them out of the directory of my package.

       
Manuel Payano's avatar
Manuel Payano
144 posts
about 16 years ago
Manuel Payano's avatar Manuel Payano

Do they really need to be helpers? Or would a library also work for you? (99.9% of the time it would)

/third_party/my_module/libraries/my_module_helper.php

$this->EE->load->library('my_module_helper');
$this->EE->my_module_helper->some_function();
       
Rob Hawkes's avatar
Rob Hawkes
5 posts
about 16 years ago
Rob Hawkes's avatar Rob Hawkes

Thanks for the prompt response DevDemon, your example using libraries and keeping everything within a class is a much cleaner way of doing it. In fact I’ve just this moment managed to get custom helpers to load into my plugin. The issue was that I was calling the helper loader method outside of of my plugin constructor so it didn’t think about looking in my plugin folder for the files.

I’m still a bit unsure about the difference between libraries and helpers, but it seems libraries are a little more powerful.

       
Manuel Payano's avatar
Manuel Payano
144 posts
about 16 years ago
Manuel Payano's avatar Manuel Payano

Glad you worked it out.

About the differences: Libraries i think are more for a “SET” of methods that belong to each other. Helper are for different helper methods. Something like static methods that do just 1 thing. In libraries you can have class variables and private methods. Which is not the case with an helper file.

I prefer libraries anyway since my IDE doesn’t recognize helper methods, so i can’t get autocomplete to work.

       
Rob Hawkes's avatar
Rob Hawkes
5 posts
about 16 years ago
Rob Hawkes's avatar Rob Hawkes

That makes sense, thanks for clearing it up.

I suppose it doesn’t really matter what I use so long as it works for me and I’m consistent.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.