【问题标题】:Error "Class 'Zend_Config_Writer_Xml' not found" when integrate Zend libary into CodeIgniter?将 Zend 库集成到 CodeIgniter 时出现“找不到类‘Zend_Config_Writer_Xml’”错误?
【发布时间】:2013-12-16 17:09:01
【问题描述】:

我复制了一些 Zend 库并将它们粘贴到 CodeIgniter 的库文件夹中。我尝试使用这段代码,没关系:

$this->zend->load('zend/json');

$data = array(
    'name' => 'Killer Whale',
    'email' => 'namnguyen2091@gmail.com',
    'website' => 'baogiadientu.com'
);

// load and encode data
$json = new Zend_Json();
$encode = $json->encode($data);
echo $encode;

//decode with static function
echo '<pre>';
print_r(Zend_Json::decode($encode));
echo '</pre>';

但是当我像下面这样编码时,它不起作用并且我得到一个错误: 致命错误:在第 83 行的 D:\Programs\xampp\htdocs\baogiadientu\application\controllers\product.php 中找不到类“Zend_Config_Writer_Xml”

$this->zend->load('zend/config');

// create the config object
$config = new Zend_Config(array(), true);
$config->production = array();

$config->production->webhost = 'baogiadientu.com';
$config->production->database = array();
$config->production->database->params = array();
$config->production->database->params->host = 'localhost';
$config->production->database->params->username = 'root';
$config->production->database->params->password = '123456';
$config->production->database->params->dbname = 'baogiadientu';

$writer = new Zend_Config_Writer_Xml(); // **here**
echo $writer->toString($config);

我关注这篇文章http://framework.zend.com/manual/2.0/en/modules/zend.config.writer.html。请帮帮我!

【问题讨论】:

    标签: php codeigniter zend-framework


    【解决方案1】:

    您正在尝试在那里做两件事 (1) 加载和实例化 Zend Config 对象,以及 (2) 对 Zend_Config_Writer_Xml 做同样的事情 - 所有这些都不包括所需的文件。

    在确保它们位于您的 include_path 中之后,您可能只需要 require("Zend/Config.php") 和 require("Zend/Config/Writer/Xml.php")

    【讨论】:

    • 但我是通过这段代码加载的 $this->zend->load('zend/config'); $config = new Zend_Config(array(), true); ?
    • 看来 Zend 代码不在您的包含路径中,将 stackoverflow.com/questions/12255888/… 作为参考,您应该能够让事情正常工作。
    【解决方案2】:

    您正在使用带有 ZF2 文档的 ZF1 库

    请在他们的网站上查看正确的文档:

    http://framework.zend.com/manual/1.12/en/zend.config.writer.introduction.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      相关资源
      最近更新 更多