0

我正在尝试运行此密码身份验证https://github.com/delight-im/PHP-Auth#creating-a-new-instance

我遵循他们的教程以及作曲家的教程。

目录:

Main
   |
   ->src
   |   |
   |   ->tools
   |         |
   |         ->authentication
   |         |
   |         ->db
   |
   ->vendor 

作曲家

 {
"name": "***",
"autoload": {
    "psr-4": {
        "Source\\": "src/"
    }
},
"authors": [
    {
        "name": "***",
        "email": "***"
    }
],
"require": {
    "delight-im/auth": "dev-master",
    "cboden/ratchet": "^0.4",
    "laravel/laravel": "^5.8",
    "twig/twig":"^2.0",
}

}

身份验证文件夹内的文件:

require_once "../../../vendor/autoload.php";

use Source\tools\db;

$dbConfig = new db\dbconfig("users");

$credentials = $dbConfig->setDb();

$pdo_connection =  new PDO("mysql:host=$localhost;dbname=$database_schema",
                   $credentials["UserName"], $credentials["PassWord"]);

$auth = new \Delight\Auth\Auth($pdo_connection);

db文件夹内的文件

namespace Source\tools\db;
class dbconfig  
{
  .....
}

我可以使用使用 Source\tools\db; 定义dbconfig所以我猜 autoload 正在为此工作。

但是当尝试使用这行代码$auth = new \Delight\Auth\Auth($pdo_connection); 我收到以下错误: 致命错误:未捕获的错误:在(为隐私删除目录)/src/tools/authentication/validate_login_credentials.php:17 中找不到类 'Delight\Auth\Auth' 堆栈跟踪:#0 {main} 抛出在

我是命名空间/作曲家的新手,请原谅我对此的无知。

有谁知道如何解决这个错误?

4

1 回答 1

1

我刚刚尝试过,它以这种方式工作,在顶部

require __DIR__ . '/vendor/autoload.php';

之后数据库配置

$db = new \PDO('mysql:dbname=my-database;host=localhost;charset=utf8mb4', 'my-username', 'my-password');

$auth = new \Delight\Auth\Auth($db);

echo get_class($auth);

没有错误,仔细检查您的供应商自动加载文件,您似乎输入了错误的路径。

使用以下内容更新您的作曲家文件

"require": {
    "delight-im/auth": "dev-master", // "delight-im/auth": "^8.1"
    "cboden/ratchet": "^0.4",
    "laravel/laravel": "^5.8",
    "twig/twig":"^2.0",
 }

代替

"delight-im/auth": "dev-master",

"delight-im/auth": "^8.1"

保存并执行 composer update 命令。

于 2019-04-13T10:43:58.730 回答