将Zend libary集成到CodeIgniter时出错“类'Zend_Config_Writer_Xml'?

问题描述:

I copy some Zend libraries and paste them into libraries folder in CodeIgniter. I try to use this code, it's ok:

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

But when I code like below, it doesn't work and I get an error: Fatal error: Class 'Zend_Config_Writer_Xml' not found in D:\Programs\xampp\htdocs\baogiadientu\application\controllers\product.php on line 83

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

I follow this article http://framework.zend.com/manual/2.0/en/modules/zend.config.writer.html. Please help me!

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

  $ this-&gt; zend-&gt; load('zend / json'); 
 
 $ data = array  (
'name'=&gt;'Killer Whale',
'email'=&gt;'namnguyen2091@gmail.com',
'website'=&gt;'baogiadientu.com'
); 
 \  n //加载和编码数据
 $ json = new Zend_Json(); 
 $ encode = $ json-&gt; encode($ data); 
echo $ encode; 
 
 //用静态函数解码
echo  '&lt; pre&gt;'; 
print_r(Zend_Json :: decode($ encode)); 
echo'&lt; / pre&gt;'; 
  code>  pre> 
 
 

但是当我 像下面的代码,它不起作用,我收到一个错误: 致命错误:在D:\ Programs \ xampp \ htdocs \ baogiadientu \ application \ controllers \ product.php中找不到类'Zend_Config_Writer_Xml'在线 83 strong> p>

  $ this-&gt; zend-&gt; load('zend / config'); 
 
 //创建配置对象
 $  config = new Zend_Config(array(),true); 
 $ config-&gt; production = array(); 
 
 $ config-&gt; production-&gt; webhost ='baogiadientu.com'; 
 $ config  - &gt; production-&gt; database = array(); 
 $ config-&gt; production-&gt; dat  abase-&gt; params = array(); 
 $ config-&gt; production-&gt; database-&gt; params-&gt; host ='localhost'; 
 $ config-&gt; production-&gt; database-&gt;  params-&gt; username ='root'; 
 $ config-&gt; production-&gt; database-&gt; params-&gt; password ='123456'; 
 $ config-&gt; production-&gt; database-&gt;  params-&gt; dbname ='baogiadientu'; 
 
 $ writer = new Zend_Config_Writer_Xml();  // **这里** 
echo $ writer-&gt; toString($ config); 
  code>  pre> 
 
 

我按照这篇文章 http://framework.zend.com/manual/2.0/en/modules/zend.config。 writer.html 。 请帮帮我! p> div>

You are trying to do two things there (1) load and instantiate a Zend Config object and (2) do the same with Zend_Config_Writer_Xml - all without including the required files.

You may just need to require("Zend/Config.php") and require("Zend/Config/Writer/Xml.php") after ensuring they are inside your include_path

You are using a ZF1 library with the ZF2 documentation

Please check the correct documentation at their website:

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