Jump to content
thirty bees forum
  • 0

Problem autoloading external clases making a module


Question

Posted

Hello. I'm making (trying to make) a carrier module for a carrier service in my country. I made an API version, based on carrier example code I found on github.

I have a module that installs, adds a new carrier and after setting it up give me the price the API returns in the checkout. Very nice.

The service also has an SDK for PHP. I tried it in a file out of TB and I can make calls and get prices. it uses 'use' and autoload function to load files. I had to add an spl_autoload_register function at the top of my .php file. I thought it would be easy to use the SDK in my module.... but I couldn't do it.

Any advice? I read a lot today...

Thanks!

1 answer to this question

Recommended Posts

  • 0
Posted

OK, I could do it. I had to create a composer.json with the directories and php fies.

    "autoload": {
        "classmap": [
"./Dir1/file.php",
"./Dir1/Dir2/file2.php",
"./Dir1/Dir3/",
       ]
    },

And then run:

composer dump-autoload -o

then in my module file:

require_once dirname(__FILE__) . '/vendor/autoload.php';

Now I can call, for example:

$val = new myclass();

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...