如何在zend框架中读取和更新配置文件

时间:2011-03-10 16:51:24

标签: zend-framework configuration-files

当我尝试更新配置文件时,抛出异常
“无法写入文件”/opt/lampp/htdocs/fashion/application/configs/d.xml“

$xml=ROOT_PATH.'/application/configs/d.xml';
$config=new Zend_Config_Xml($xml,null,true);
$conf_arr=$config->toArray();
$conf_arr['name']='somebody';
$conf_writer=new Zend_Config_Writer_Xml();
try 
{
  $conf_writer->write($xml,new Zend_Config($conf_arr),false);
} catch (Exception $e) 
{
  echo '<h1 style="color:red;">'.$e->getMessage().'</h1>';
}

xml文件

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <name>ahmed</name>
    <living>Saudi Arabia</living>
</data>

当我将它保存到另一个文件时,它可以工作但似乎锁定了如何解锁

1 个答案:

答案 0 :(得分:2)

我认为你的“d.xml”不是Apache可写的吗?

您的“configs”目录肯定是可写的(这与新文件有关),但不是您的默认文件。