directus-8-extensions
directus-8-extensions copied to clipboard
Adding Helpers class to Directus
HI, i tried to add Helpers to running Directus instance by changing the composer configuration file. I can't make it work can you please share advice to configure helpers on existing directus instance. Thanks in advance
Can you share what you have so far and what helper you are trying to use?
Just in case, in the helper/functions.php, you have this snippet:
/*
AutoLoad - Helper Files - Should Run at application.boot!
*/
$helpers = scandir(__DIR__);
foreach( $helpers as $file )
{
if ('.' === $file || '..' === $file || __FILE__ === $file) continue;
include_once($file);
}
You then want to include this file in the config/
After that, you can do:
use Directus\Custom\Helpers;
I am trying to add CSV export feature but I can't make it work I have the error with helpers not initialized.
Can you please share how you include this file in /config/*.php file Thanks in advance
To include all the helpers in the project configuration:
/*
AutoLoad - Helper Files - Should Run at application.boot!
*/
$helpers = scandir(realpath( dirname(__DIR__) . '/public/extensions/custom/helpers' ));
foreach( $helpers as $file )
{
if ('.' === $file || '..' === $file || __FILE__ === $file) continue;
include_once($file);
}
or you can include the helper directly in your hook or endpoint file.