Welcome Guest, Not a member yet? Register   Sign In
Loading vendor helper into global namespace
#1

Hey! Is there a convenient way to load a helper from vendor package into global namespace?

Currently what works (and what I could not find anywhere by googling) is to set it into App/Config/Autoload.php

PHP Code:
public $files = [
    APPPATH '../vendor/MyName/MyPackage/src/Helpers/myhelper_helper.php'
]; 

Also, I have tried to use VENDORPATH here but it's undefined by the time of Autoload.php file gets ignited.


In the docs https://codeigniter.com/user_guide/general/helpers.html it states that only way to load helper is by:

PHP Code:
helper('myhelper'); 

But I have an essential helper in my vendor/myname/pacakgename/src/Helpers/myhelper_helper.php that I would like to be accessible trough out my application at all times.
I have tried:

Setting load call into vendor/..../composer.json

PHP Code:
{
    "autoload": {
        "psr-4": {"MyName\\MyPackage\\""src/"},
        "files": [
            "src/Helpers/myhelper_helper.php"
        ]
    }


Creating a vendor/myname/mypackage/src/Config/Autoload.php and setting it up as part of $files array.
This is not getting discovered or i'm doing something very wrong.

Will anything be changed in this regard or is what I described as working solution the way to go?
Or did I misunderstood anything and there already is a very convenient and elegant solution for this?
Reply


Messages In This Thread
Loading vendor helper into global namespace - by stopz - 05-31-2021, 12:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB