2017-11-02 1 views
0

codeigniter 라이브러리에서 apache 중고 ​​안경을 사용하고 싶습니다.
다음 코드가 있습니다. 나는 파일을 검사했고 그것들이 존재한다.
PHP 버전은 PHP 5.6.31
중고품 혼란 스럽다가codeigniter에서 아파치 절약을 사용하면 클래스를 찾을 수 없습니다.

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); 

0.10.* 다음은 나에게 오류 표시입니다 :

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

을 내가 대해, 구글과 보안 목표 명세서에 그냥이 link이이 문제를 검색하지만, 내 문제를 해결하지 못한다.

내가 뭘 잘못했는지 알려주십시오.

감사합니다.


이제 문제는 단지 파일을로드 PHP를 require FUNC를 사용하여 해결된다.
하지만 여하튼 덕분에 오랫동안 도움이되었습니다.
코드는 타격 : 당신이 네임 스페이스를 사용할 때

$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); 

답변

0

, 사용한다 작곡가

당신 수있는 config/config.php 파일에 $config['composer_autoload'] = TRUE; 이 옵션은 TRUE로 수정되고 기본값은 FALSE입니다.

여기에주의하십시오. TRUE를 수정하면 CI는 자동으로 application/vendor/autoload.php으로로드됩니다. 프로젝트 루트 디렉토리에 공급 업체 디렉토리가 있고 동일한 레벨에 index.php이있는 경우 $config['composer_autoload'] = realpath (APPPATH.'../vendor/ autoload.php'); 작곡가를 소개하는 방법을 사용할 수 있습니다.

+0

절약을로드하려면 작곡가를 사용해야합니까? 프로젝트에서 작곡가를 사용하지 않습니다. 다른 방법이 있습니까? –

+0

Ci는 네임 스페이스에서 지원되지 않습니다. 작곡가를 사용하고 싶지 않고 Ci를 사용하려면 네임 스페이스를 사용하지 마십시오. 네임 스페이스를 사용하려면 laravel – long

+0

을 사용하는 것이 좋습니다. CI가 네임 스페이스에서 지원되지 않습니다. PHP의 버전이 5.3 이상인 경우 네임 스페이스가 모두 지원됩니다. –

관련 문제