Hi there. What I did was creating a components folder and place my helper file in it. Now, assuming that you use the “Advance Application Template” which has both ‘frontend’ and ‘backend’, it would be place inside appname\common\components. This would make the helper available in both ‘frontend’ and ‘backend’.
Your helper namespace should be like this:-
appname/common/components/helpers.php
<?php
namespace common\components;
class Helpers
{
public static function random()
{
return rand(1,5);
}
}
?>
Then in your main-local.php, you need to load your helper class.
Unfortunately I didn’t want the class autoloaded - its only used in one section of the application and autoloading felt a bit like a sledgehammer to crack a nut.
In the end I’ve simply stored it in a sub-folder of the ‘vendors’ folder:
\vendors\myorganisation\helpers\Fred.php
containing:
<?php
namespace vendor\myorganisation\helpers;
Class Fred {
//.... various static methods
}