【问题标题】:Class not found showing Php找不到显示 Php 的类
【发布时间】:2019-04-04 08:29:18
【问题描述】:

我的 index.php 文件存在于public_html/myapp/files 目录中,我正在尝试使用存在于同一目录public_html/myapp/files 中的库。但我收到错误

在中找不到类“SightengineClient” /home/public_html/myapp/files/index.php 在第 7 行

我哪里错了? 这是我的代码

namespace Tests;
use SightengineClient;
$client = new SightengineClient('myapikey', 'secretkey');
$output = $client->check(['nudity'])->set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg');
echo "<pre>";print_R($output);

【问题讨论】:

  • 您的要求/包含在哪里?
  • 你在项目中使用 composer 吗?
  • @MohammedYassineCHABLI :不,我只是打开我的 cpanel 并从 github 上传下载的代码
  • 您必须在文件中包含定义类 SightengineClient 的文件。 使用关键字不会导入类定义
  • 试试这个$client = new \SightengineClient('myapikey', 'secretkey');

标签: php path


【解决方案1】:

如果您不使用 composer 管理您的项目(生成自动加载),使用 use kewyord 将不包含该类,您是否可以通过这种方式要求该文件:

require_once('path to SightengineClient file');

$t = new SightengineClient;

使用 require_once 将确保您只包含一次 文件。

【讨论】:

    猜你喜欢
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2017-05-24
    • 2015-04-04
    • 2021-09-20
    相关资源
    最近更新 更多