简体   繁体   中英

Class not found error with composer autoload

I must be making a simple error, I have not used Composer before now. I have followed the instructions on the GitHub page , but I'm getting a Class 'ZCRMRestClient' not found error when I load the page.

composer.json:

{
    "require": {
        "zohocrm/php-sdk": "^2.0"
    }
}

PHP is

require 'vendor/autoload.php';

$configuration = array(
    'client_id' => '1000.***',
    'client_secret' => '***',
    'redirect_uri' => '***',
    'currentUserEmail' => '***',
);

ZCRMRestClient::initialize($configuration);

$contacts = ZCRMRestClient::getModule(“Contacts”);

echo "<pre>\n";
print_r($contacts);
echo "\n</pre>";

I've tried \\ZCRMRestClient::initialize($configuration) but that hasn't helped.

There is new sdk 3.0 available, and the old sdk 2.0 is moved to:

"require": {
    "zohocrm/php-sdk-archive": "^2.0"
}

I'm going to assume you've executed the composer require zohocrm/php-sdk command, or potentially added the requirement straight into your project's composer.json by hand.

Make sure you're importing the correct namespace for the library - in this case it seems to be zcrmsdk\\crm\\setup\\restclient\\ZCRMRestClient

You should write use zcrmsdk\\crm\\setup\\restclient\\ZCRMRestClient; at the top of the file then invoke methods as you currently do.

Alternatively, you can invoke methods as in the following example: \\zcrmsdk\\crm\\setup\\restclient\\ZCRMRestClient::initialize($configuration);

After that the most likely problem is that your autoload file doesn't contain a reference to your library.

composer dump-autoload should fix that (from the command line.)

And finally perhaps you are not requiring the vendor folder correctly!

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