Class 未发现作曲家自动加载错误

Class not found error with composer autoload

我一定是犯了一个简单的错误,我以前没有使用过 Composer。我已按照 GitHub page 上的说明进行操作,但在加载页面时出现 Class 'ZCRMRestClient' not found 错误。

composer.json:

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

PHP 是

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>";

我试过 \ZCRMRestClient::initialize($configuration) 但没有用。

我假设您已经执行了 composer require zohocrm/php-sdk 命令,或者可能手动将需求直接添加到项目的 composer.json 中。

确保您为库导入了正确的命名空间 - 在本例中似乎是 zcrmsdk\crm\setup\restclient\ZCRMRestClient

您应该在文件顶部写上 use zcrmsdk\crm\setup\restclient\ZCRMRestClient;,然后像现在一样调用方法。

或者,您可以调用方法,如下例所示:\zcrmsdk\crm\setup\restclient\ZCRMRestClient::initialize($configuration);

之后最有可能的问题是您的自动加载文件不包含对您的库的引用。

composer dump-autoload 应该解决这个问题(从命令行。)

最后,也许您没有正确要求供应商文件夹!

有新的sdk 3.0可用,旧的sdk 2.0移至:

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