jldavis76 jldavis76 - 18 days ago 4
PHP Question

Using Cloud Convert API with CodeIgniter 2.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!

Answer

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();
    }
}
Comments