【问题标题】:Including Zend Library within Codeigniter在 Codeigniter 中包含 Zend 库
【发布时间】:2013-07-24 23:40:05
【问题描述】:

所以我主要尝试安装一些 Zend Framework 组件,以便我可以使用 google API picasa 库。

我尝试将 Zend 库添加到我的

codeigniter-> 应用程序-> 库

然后运行$this->load->library('Zend'); 但我收到了

无法加载请求的类:zend

然后我尝试这样做

$clientLibraryPath = '/usr/local/lib/php/Zend/Gdata';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);

错误

> Exception thrown trying to access Zend/Loader.php  using
> 'use_include_path' = true. Make sure you  include Zend Framework in
> your include_path  which currently  contains:
> .:/usr/share/php:/usr/share/pear:/usr/local/lib/php/Zend/Gdata

我不确定实际路径应该是什么我还将 Zend 库上传到 users/local/lib/php。我做错了什么?

【问题讨论】:

标签: php codeigniter zend-framework


【解决方案1】:

看到这个: 您需要在 libraries 中创建文件 Zend.php 如下图:

并将这段代码粘贴到其中:

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Zend
{

    public function __construct($class = NULL)
    {

        ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries');

        if ($class) {

            require_once (string) $class . EXT;

            log_message('debug', "Zend Class $class Loaded");
        } else {

            log_message('debug', "Zend Class Initialized");
        }
    }

    public function load($sClassName)
    {

        require_once (string) $sClassName . EXT;

        log_message('debug', "-> Zend Class $sClassName Loaded from the library");
    }

}

就是这样。现在从 Controller 中的方法调用你需要的库。 这里我展示了一个加载 Picasa 网络相册 的示例。

    $this->load->library('zend');
    $this->zend->load('Zend/Loader');
    Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_Photos');
    Zend_Loader::loadClass('Zend_Http_Client');

用另一个例子来加载 Google Spreedsheet。

$this->load->library('zend');
$this->zend->load('Zend/Gdata/Spreadsheets');
$oSpreadSheet = new Zend_Gdata_Spreadsheets();
$entry = $oSpreadSheet->newCellEntry();
$cell = $oSpreadSheet->newCell();
$cell->setText('My cell value');
$cell->setRow('1');
$cell->setColumn('3');
$entry->cell = $cell;
var_dump(  $entry );

更多信息see this

【讨论】:

  • 我实际上必须将 EXT 设置为“.php”才能让我的加载不确定这是否是 CI 版本 3 问题。
猜你喜欢
  • 1970-01-01
  • 2011-08-13
  • 1970-01-01
  • 1970-01-01
  • 2011-01-21
  • 2011-01-25
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
相关资源
最近更新 更多