Search code examples
objectlaravel-4plivo

how to call a class function of an included php file Laravel 4


I have a php file plivo.php in app/plivo folder. This included in my controller like,

require app_path().'/plivo/plivo.php';

The plivo.php contains a class, RestAPI .

When I try to create an object like,

        $auth_id = "Your AUTH_ID";
        $auth_token = "Your AUTH_TOKEN";

        $p = new RestAPI($auth_id, $auth_token);

Produce an error:

Class 'Controllers\Account\RestAPI' not found

How can I create this object ?


Solution

  • As your class is not namespaced - try and call it like this:

        $auth_id = "Your AUTH_ID";
        $auth_token = "Your AUTH_TOKEN";
    
        $p = new \RestAPI($auth_id, $auth_token);
    

    Notice the \ before RestAPI