简体   繁体   中英

PHP Fatal error: Uncaught Error: Class 'Api' not found

I am new to PHP. When I tried to run the below code getting the following error.

Error Message:

PHP Fatal error:  Uncaught Error: Class 'Api' not found in C:\Users\cpa\Downloads\b\vendor\php1.php:4
Stack trace:
#0 {main}
  thrown in C:\Users\cpa\Downloads\b\vendor\php1.php on line 4

Api.php is there in the following location. I tried n different ways to include the class but no luck. Please let me know how to resolve this error message.

C:\\Users\\cpa\\Downloads\\b\\vendor\\brightlocal\\api\\src\\BrightLocal

Code:

<?php
require 'vendor/brightlocal/api/src/BrightLocal/Api.php';

$api = new Api('key', 'secret_key');

// get a list of clients
print_r($api->call('/v2/clients/get-all'));

// get a client
print_r($api->call('/v2/clients/get', array(
    'client-id' => 1059
)));

// get LSRC report list
print_r($api->call('/v2/lsrc/get-all'));

// get LSRC report
print_r($api->call('/v2/lsrc/get', array(
    'campaign-id' => 50
)));

// get CT report list
print_r($api->call('/v2/ct/get-all'));

// get a CT report
print_r($api->call('/v2/ct/get', array(
    'report-id' => 259
)));

There are several things that are a bit off:

  • Why are you in the vendor folder? This things is actually used for external libraries that you download via composer or where you place the autoloader.
  • The require (why not require_once ?) is in the wrong folder. As can be seen from the error message. My suggestion is that you move the frontcontroller (php1.php) out of the vendor folder and in the folder which has the vendor folder as a subfolder: C:\\Users\\cpa\\Downloads\\b and setup your system from there anew.

    require 'vendor/brightlocal/api/src/BrightLocal/Api.php';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM