【发布时间】:2019-08-01 03:22:12
【问题描述】:
我正在尝试使用从带有 composer 的 packagist 安装的存储库中的一个类。我正在编写的 PHP 文件位于我的 Project 文件夹下,以及位于 Project>vendor 中的存储库。
include "Project/vendor/autoload.php";
include "Project/vendor/smartcat/smartcat-api/src/SmartCAT/API/SmartCAT.php";
use SmartCAT\API\SmartCAT;
use SmartCAT\API\Model\CreateProjectWithFilesModel;
这是我文件的顶部,它是我从存储库中检索 smartcat 类的方式。当我尝试使用我写的$sc= new SmartCAT($login, $password); 的类时。这会导致错误:PHP Fatal error: Uncaught Error: Class 'SmartCAT\API\SmartCAT' not found in C:\Users\...\Project\createProject.php:20。当我运行get_included_files() 时,会包含必要的文件。我不确定为什么我无法使用该课程。
【问题讨论】:
-
你使用composer,除了
autoload.php之外,不需要包含其他文件。 -
我删除了那行,我仍然得到同样的错误。
-
您是否将类路径添加到 composer.json
classmap或psr-4? -
我的作曲家。 json 看起来像 '{ "require": { "smartcat/smartcat-api": "^2.0" } } ' 如何添加类路径?
标签: php class composer-php repository packagist