代码之家  ›  专栏  ›  技术社区  ›  code.g

在codeigniter中使用apache thrift时,未找到show me类

  •  0
  • code.g  · 技术社区  · 7 年前

    我想在codeigniter库中使用apache thrift。
    我有以下代码。我已经检查了这些文件,它们是存在的。
    PHP 5.6.31
    0.10.*

    use Thrift\Transport\TSocket;
    use Thrift\Transport\TBufferedTransport;
    use Thrift\Transport\THttpClient;
    use Thrift\Protocol\TBinaryProtocol;
    use Thrift\Exception\TException;
    use Thrift\ClassLoader\ThriftClassLoader;
    use \test\MyServiceClient;
    
    class Cds2thriftclass extends Rootclass {
        private $_thrift_uri = "";
        private $_thrift_port = "";
        private $_timeout = 5000;
    
        private $transport;
        private $protocol;
        private $client;
    
        public function __construct() {
            parent::__construct();
            $this->_thrift_uri = 127.0.0.1;
            $this->_thrift_port = 8899;
    
            $THRIFT_ROOT = APPPATH . 'libraries/thrift10';
            require_once $THRIFT_ROOT.'/Thrift/ClassLoader/ThriftClassLoader.php';
    
            $GEN_DIR = $THRIFT_ROOT . '/Thrift/packages';
    
            $loader = new ThriftClassLoader();
            $loader->registerNamespace('Thrift', $THRIFT_ROOT);
            $loader->registerDefinition('test', $GEN_DIR);
            $loader->register();
    
            $this->transport = new TSocket($this->_thrift_uri, $this->_thrift_port);
            $this->transport->setRecvTimeout($this->_timeout);
            $this->transport = new TBufferedTransport($this->transport, 1024, 512);
            $this->protocol = new TBinaryProtocol($this->transport);
            $this->client = new \test\MyServiceClient($this->protocol);
    

    Class 'test\MyServiceClient' not found in /apps/blog/application/libraries/mythriftclass.php 
    

    我在谷歌和ST中搜索这个问题,就是这个 link 这是关于,但它不能解决我的问题。

    请让我知道我做错了什么。


    现在问题解决了,只需使用php即可 require func加载文件。
    但无论如何,谢谢龙的帮助。
    代码为blow:

        $THRIFT_ROOT = APPPATH . 'libraries/thrift10';
        require_once $THRIFT_ROOT.'/Thrift/ClassLoader/ThriftClassLoader.php';
    
        $GEN_DIR = $THRIFT_ROOT . '/Thrift/packages';
    
        $loader = new ThriftClassLoader();
        $loader->registerNamespace('Thrift', $THRIFT_ROOT);
        $loader->registerDefinition('test', $GEN_DIR);
        $loader->register();
    
        $this->transport = new TSocket('127.0.0.1', 8899);
        $this->transport->setRecvTimeout($this->_timeout);
        $this->transport = new TBufferedTransport($this->transport, 1024, 512);
        $this->protocol = new TBinaryProtocol($this->transport);
    
        require_once $THRIFT_ROOT . '/Thrift/gen-php/test/Types.php';
        require_once $THRIFT_ROOT . '/Thrift/gen-php/test/Cds2APIService.php';
    
        $this->client = new MyServiceClient($this->protocol);
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Virb    7 年前

    当您使用命名空间时,应该使用composer

    你可以 $config['composer_autoload'] = TRUE config/config.php 文件此选项修改为TRUE,默认值为FALSE

    请注意。如果修改TRUE,则会自动加载CI application/vendor/autoload.php index.php 在同一级别上,您可以使用 $config['composer_autoload'] = realpath (APPPATH.'../vendor/ autoload.php'); 介绍作曲家的方法