Codeigniter中未加载第三方php库

Codeigniter中未加载第三方php库,php,codeigniter,encryption,encoding,Php,Codeigniter,Encryption,Encoding,我正在为我的应用程序使用codeigniter。我想散列我的数据库ID。因此,我使用以下php库: 该库位于application/libraries/hashids.php中 这是我的控制器代码。我尝试过不同的方法,比如文件名大写等等,但是它说无法加载请求的类 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); //require_once(APPPATH.''); //require_o

我正在为我的应用程序使用codeigniter。我想散列我的数据库ID。因此,我使用以下php库:

该库位于application/libraries/hashids.php中

这是我的控制器代码。我尝试过不同的方法,比如文件名大写等等,但是它说无法加载请求的类

<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//require_once(APPPATH.'');
//require_once(APPPATH.'libraries/hashids.php-master/src/Hashids.php');


class Pages extends CI_Controller {
  public function __construct() {

    parent::__construct();

    // include APPPATH . 'libraries/Hashids/Src/HashidsInterface.php';
    //include APPPATH . 'libraries/Hashids/Src/Hashids.php';

    //require_once(APPPATH.'libraries/Hashids/Src/HashidsInterface.php');
    require_once(APPPATH.'libraries/Hashids/Src/Hashids.php');

    //use Hashids/Src/Hashids.php;

    $this->load->model('post_model');
    $this->load->model('comment_model');
    $this->load->model('media_model');
    //$this->load->library('Hashids');
  }


  public function postFunc() {

    $this->load->library('hashids');  
    //$hashids = new hashids(); 

    $hashids->encode(1);
    echo $hashids;
    exit(); 
  }

尝试使用composer,我认为现在和将来使用库会更容易

首先执行命令
composer require hashids/hashids
或将lib添加到require对象中的
composer.json
文件中,如下面所示,然后执行命令
composer install

{
    "description": "The CodeIgniter framework",
    "name": "codeigniter/framework",
    "type": "project",
    "homepage": "https://codeigniter.com",
    "license": "MIT",
    "support": {
        "forum": "http://forum.codeigniter.com/",
        "wiki": "https://github.com/bcit-ci/CodeIgniter/wiki",
        "slack": "https://codeigniterchat.slack.com",
        "source": "https://github.com/bcit-ci/CodeIgniter"
    },
    "require": {
        "php": ">=5.3.7",
        "hashids/hashids": "3.0.0"
    },
    "suggest": {
        "paragonie/random_compat": "Provides better randomness in PHP 5.x"
    },
    "require-dev": {
        "mikey179/vfsStream": "1.1.*",
        "phpunit/phpunit": "4.* || 5.*"
    }
}
在配置文件
application/config/config.php
中,确保设置了composer自动加载脚本的路径,如下所示:

$config['composer_autoload'] = 'vendor/autoload.php';
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

  use Hashids\Hashids;    

  class Pages extends CI_Controller {

      public function __construct() {        
          parent::__construct();

          $hashids = new Hashids(); // use the lib

          $this->load->model('post_model');
          $this->load->model('comment_model');
          $this->load->model('media_model');
          //$this->load->library('Hashids');        
      }
通常,
autoload.php
文件位于在项目根文件夹上创建的
vendor
文件夹中

然后在代码中尝试使用指定名称空间的lib
use Hashids\Hashids位于脚本顶部,如下所示:

$config['composer_autoload'] = 'vendor/autoload.php';
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

  use Hashids\Hashids;    

  class Pages extends CI_Controller {

      public function __construct() {        
          parent::__construct();

          $hashids = new Hashids(); // use the lib

          $this->load->model('post_model');
          $this->load->model('comment_model');
          $this->load->model('media_model');
          //$this->load->library('Hashids');        
      }

您是否遵循了正确的类命名约定?-你为什么不把它和composer一起加上呢?请阅读如何加载和创建库:你没有展示你是如何加载库的。通过配置,还是手动?请显示代码。如果我不想用composer添加代码,该怎么办。有没有其他方法可以做到这一点?事实上,我的网站是在线的,我有FTP凭据,所以我如何才能在线安装composerServer@user9496246如果您不能访问终端,我认为您不能使用composer。您可以尝试在本地运行该项目,然后使用FTPthanks进行更新以获得帮助,但不知何故,我认为这个问题是HASHIDs类使用接口来实现其功能,这可能就是它不加载该类的原因