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
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.
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.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.