douzhan8652 2018-04-14 19:58
浏览 266
已采纳

无法使用composer vendor作为codeigniter库

I am trying to use this (https://github.com/Achse/geth-jsonrpc-php-client) library using composer and codeigniter. But I am getting below error:

Type: Error

Message: Class 'GuzzleClient' not found

Filename: /var/www/html/test/application/libraries/Ethereum.php

Line Number: 7

And below is my library code:

<?php

class Ethereum
{
    public function __construct()
    {
        $httpClient = new GuzzleClient(new GuzzleClientFactory(), 'localhost', 8545);
        $client     = new Client($httpClient);

        return $client;
    }

}

Composer is wel loaded as other dependancies are working fine. Not able to find out the issue. plz help

  • 写回答

1条回答 默认 最新

  • dongwen7371 2018-04-14 20:19
    关注

    When using Composer you typically have to include an autoload.php file. You also need to used namespaces for the Composer dependencies.

    Usually the vendor directory is on the same level as application so it's handy to define a constant to point to the vendor directory.

    define('VENDOR', substr(FCPATH, 0, strpos(APPPATH, 'application/')) . "vendor/");
    

    Your library maybe needs to look more like this.

    <?php
    require VENDOR . 'autoload.php';
    
    //I'm not certain this is the correct namespace but hopefully you get the idea
    use Achse\GethJsonRpcPhpClient; 
    
    class Ethereum
    {
        protected $httpClient;
        protected $client;
    
        public function __construct()
        {
            $this->httpClient = new GuzzleClient(new GuzzleClientFactory(), 'localhost', 8545);
            $this->client     = new Client($httpClient);
        }
    
        //example using the class property $client
        public getResult()
        {
            return $this->client->callMethod('eth_getBalance', ['0xf99ce9c17d0b4f5dfcf663b16c95b96fd47fc8ba', 'latest']);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法