【问题标题】:Loading google api client library in codeiniter在 codeigniter 中加载 google api 客户端库
【发布时间】:2015-03-23 22:14:03
【问题描述】:

首先我将 Google 文件夹复制到 codeigniter 框架中的 application/third_party。

然后是应用程序/库中的 google.php

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
set_include_path(APPPATH . 'third_party/' . PATH_SEPARATOR . get_include_path());
require_once APPPATH . 'third_party/Google/Client.php';

class Google extends Google_Client {
    function __construct($params = array()) {
        parent::__construct();
    }
}

然后我创建了一个名为 googleClass.php 的控制器

<?php
class GoogleClass extends CI_Controller {
    function __construct($params = array()) {
    parent::__construct();
}
public function index(){

    $this->load->library('google');
    echo $this->google->getLibraryVersion();
   }
}

但我收到以下错误...

Fatal error: require_once(): Failed opening required '' (include_path='application/third_party/;.;C:\xampp\php\pear') in C:\xampp\htdocs\csvinsert\application\third_party\Google\Client.php on line 18

我做错了什么??

【问题讨论】:

    标签: php codeigniter google-api-php-client


    【解决方案1】:

    请尝试以这种方式加载您的库:include_once APPPATH . "libraries/third_party/Google/Client.php";

    【讨论】:

      【解决方案2】:

      我假设您在application/third_party 目录中拥有autoload.php,而在application/third_party/Google 目录中的其余源代码。

      application/libraries/google.php 中删除这一行。

      set_include_path(APPPATH . 'third_party/' . PATH_SEPARATOR . get_include_path());
      

      现在代码 google.php 将是

      <?php
      if (!defined('BASEPATH')) exit('No direct script access allowed');
      
      require_once APPPATH . 'third_party/Google/Client.php';
      
      class Google extends Google_Client {
          function __construct($params = array()) {
              parent::__construct();
          }
      }
      

      这将消除该错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-11
        • 1970-01-01
        • 2017-10-18
        相关资源
        最近更新 更多