如何解决 fusionauth php client error 'FusionAuthClient' not found?

How do I solve fusionauth php client error 'FusionAuthClient' not found?

当我关注https://github.com/FusionAuth/fusionauth-php-client

我可以看到错误:

PHP Fatal error:  Uncaught Error: Class 'FusionAuthClient' not found ... on line 6

我的申请是这样的:

  First application
  <?php
  require_once 'FusionAuthClient.php';

  $apiKey = "7W-yBfeXfniDhu8PR_h0dGkSsPDJlpUYuP9rP2xXd_4";
  $client = new FusionAuthClient($apiKey, "http://localhost:9011");

第 6 行是最后。

作曲家说一切都是对的

$ composer require fusionauth/fusionauth-client
Using version ^1.6 for fusionauth/fusionauth-client
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing fusionauth/fusionauth-client (1.6.1)
    Downloading: 100%         

Writing lock file
Generating autoload files

FusionAuthClient.phpClientResponse.phpRESTClient.php 与我的测试脚本在同一目录中。

你能给我指出正确的方向吗这个问题的原因是什么?

看起来require_once函数路径无效

使用 "require" 而不是 "require_once" 时,您是否有同样的错误?

你看过FusionAuthClient.php文件的第一行了吗?显然不是。

namespace FusionAuth;

因此,class 不在全局命名空间中,因此您需要告诉 php 它在哪个命名空间中:

$client = new FusionAuth\FusionAuthClient($apiKey, "http://localhost:9011");

不客气。