doupeng8419 2017-04-18 17:30
浏览 48
已采纳

PHP Composer - php-sql-query-builder

I just figured out how to install and use PHP composer and used it to instal php-sql-query-builder to my project. The system created the vendor folder, etc. however I am having issues using classes within the package. It gives me the following error, any suggestions on how I can fix this?

Fatal error: Uncaught Error: Class 'NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder' not found in D:\Documents\CadetPortal\php\lib\login.class.php on line 15

Login.class.php

    require_once ("core.class.php");
    require_once ("../../vendor/autoload.php");

    use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;

    class LoginSystem {
        private $core;
        private $builder;
        private $config;

        function __construct(){
            $this->core = new coreFunctions();
            $this->builder = new GenericBuilder();
            $this->config = require('core.config.php');
        }
//....
    }

EDIT

fncregister.php

require_once "../../vendor/autoload.php";
$LoginManager = new \ThomasSmyth\LoginSystem();

echo $LoginManager->Register($_POST["StrSurname"], $_POST["StrForename"], $_POST["StrEmail"], $_POST["StrPassword"], $_POST["DteDoB"], $_POST["StrGender"], $_POST["StrToken"]);

composer.json

{
    "require": {
        "nilportugues/sql-query-builder": "^1.5"
    },
    "autoload": {
        "psr-4": {
            "ThomasSmyth\\": "php/lib/"
        }
    }
}
  • 写回答

1条回答 默认 最新

  • drxrgundk062317205 2017-04-18 17:56
    关注

    Your class source files shouldn't have any require_once statements at all in them. Follow the PSR-4 spec for naming. Put your classes in a namespace to avoid collision with other classes you might include via composer. Then put one class in one file, named the same as the class. For example, the LoginSystem class should be in a file named LoginSystem.php.

    namespace MyNamespace;
    
    class LoginSystem
    {
        ...
    }
    

    Then set your composer.json to point your namespace to your source directory:

    "autoload": {
        "psr-4": {
            "MyNamespace\\": "src/"
        }
    },
    

    Now, your main app invoker or front controller should be the only place that includes the autoloader:

    require_once 'vendor/autoload.php';
    $login = new \MyNamespace\LoginSystem();
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 需要数据库运行的图片
  • ¥15 如何获取vue-video-editor?
  • ¥100 vs2019 mfc程序如何实现64*64/48*48大小的真彩色工具栏
  • ¥15 全志v3s耳机音频输出口怎么外接功放
  • ¥15 华为ensp使用基本ACL限制公司网络访问
  • ¥15 帮我做下照片上的PLC题
  • ¥15 labview2022 使用modbus报缺少依赖?
  • ¥15 谷歌地图是不是不开通结算功能,api会使用不了哦
  • ¥15 unity腾讯云对象存储机型适配
  • ¥15 求全国交通咨询模拟代码,要求如下,可以完全在dev c++运行