1

Does anyone have any experience using the cloudconvert-php wrapper? Here is the GitHub page for it: https://github.com/cloudconvert/cloudconvert-php.

I have installed it using composer, and updated my autoload.php file in the vendor folder with the necessary:

require_once __DIR__ . '/autoload.php';

But when I go to use the API, I get the following error:

Fatal error: TestController cannot use CloudConvert\Api - it is not a trait in /controllers/testController.php on line...

I cannot figure out what I am doing wrong, so any help is greatly appreciated.

Thank you in advance!

muenchdo
  • 2,161
  • 1
  • 17
  • 30
jldavis76
  • 812
  • 2
  • 15
  • 42
  • Note: If your using CI3 You should rename your test controller to Test_controller.php only have first letter upper case. `class Test_controller extends CI_Controller {}` –  Jan 08 '16 at 21:31

1 Answers1

0

Your use statement is at the wrong position.

it is not a trait in /controllers/testController.php on line

Without seeing the source, this error indicates that you are trying to do something like:

<?php

trait MyTrait {
    function getFoo() { }
}

class MyClass extends MyBaseClass {
    use MyTrait;                      // <---- trait include, inside the class
    /* ... */
}

To solve the issue, please move the use to the outside of the class, like so:

<?php 

use CloudConvert\Api;                    // <---- class include

class TestController {

    function test() {
         $this->api_key = getenv('API_KEY');
         $this->api = new Api($this->api_key);    // instantiate

         $this->api->doStuff();
    }
}
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141